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;
}