GCD The Largest
来源:互联网 发布:java项目开发案例介绍 编辑:程序博客网 时间:2024/05/18 14:27
GCD The Largest
DESCRIPTION
Given N, print the largest number that can be achieved by taking gcd (greatest common divisor) of any two i and j where i != j ,and 1<=i; j<=N.
Input
First line of input will contain the number of test cases,T<=2000. Then T
cases follow. For each case,there is a line containing one integer N where 2<= N<=10^18.
Output
For each case, print one line containing a single integer which is the largest gcd of all pairs of numbers between 1 to N.
Sample input
2
2
5
Sample output
1
2
解题:直接用gcd会超时
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;int main(){ long long n,t,ans; while(~scanf("%lld",&n)) { while(n--) { scanf("%lld",&t); if(t%2) ans = (t - 1)/2; else ans = t/2; cout<< ans <<endl; } } return 0;}
0 0
- GCD The Largest
- GCD The Largest
- 最大公约数-GCD The Largest
- UVA11324 The Largest Clique
- The Largest Clique
- 1094.The Largest Generation
- 1094. The Largest Generation
- 1094. The Largest Generation
- pat1094 The Largest Generation
- 1094. The Largest Generation
- The Largest Generation (25)
- 1094 The Largest Generation
- PAT1005-The Largest Generation
- 1094. The Largest Generation
- 1094. The Largest Generation
- 1094. The Largest Generation
- The Largest Generation (25)
- 1094. The Largest Generation
- OpenWRT下载与编译
- 大道至简,心守平常
- Java中的数组
- 博为峰JavaEE技术文章 ——MyBatis Mapper TypeHandler
- 数值分析与算法——读书笔记(一)
- GCD The Largest
- MySQL Group Replication的RECOVERING状态深度理解
- Oracle使用强制索引注意事项
- 屏幕适配图片
- MyBatis Generator无法生成selectByPrimaryKey(),updateByPrimaryKey()的解决方法
- ubuntu配置vim编辑器
- Py第十九问 Your local changes would be overwritten by merge. Commit, stash or revert them to proceed.
- Glide进阶详解(九)
- 字符流中read()方法返回值的问题