HDU 4627 There are many unsolvable problem in the world.It could be about one or about zero.But this time it is about bigger number.

题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82974#problem/E

解题思路:数论,从一个数的中间开始往两边找,找到两个互质的数就是,若这个数为奇数,则就是(n/2)*(n-n/2),若这个数是偶数,则还需要判断这个数的一半是否是偶数,若是偶数,则就是(n/2+1)*(n/2-1),若是奇数,则就是(n/2+2)*(n/2-2)

程序代码:

#include <iostream>
#define l  long long
using namespace std;

int main()
{
l t;cin>>t;
while(t--)
{   l n;
    cin>>n;
    if(n==2)
        cout<<1<<endl;
    else
    {
        if(n%2)
            cout<<(n/2)*(n/2+1)<<endl;
        else
        {
            if((n/2)%2)
                cout<<(n/2+2)*(n/2-2)<<endl;
            else
                cout<<(n/2+1)*(n/2-1)<<endl;
        }
    }
}
       return 0;
}

 

你可能感兴趣的:(number)