GCD The Largest

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值