现在的位置: 首页 > 综合 > 正文

水题

2012年06月05日 ⁄ 综合 ⁄ 共 582字 ⁄ 字号 评论关闭
#include<stdio.h>
#include<math.h>
int main()
{
    int n,t,m;
    scanf("%d",&m);
    while(m--)
    {
        scanf("%d",&n);
        t=(int)sqrt(n*1.0);
        for(;t>=1;t--)
        {
            if( n%t==0 && (n/t-t)%2==0 && n/t!=t )
            break;
        }
        if(t==0) printf("-1\n");
        else printf( "%d\n",(n/t-t)/2 );
    }
    return 0;
}
Problem Description
For a given positive integer n, please find the smallest positive integer x that we can find an integer y such that y^2 = n +x^2.
 
Input
The first line is an integer T, which is the the number of cases.
Then T line followed each containing an integer n (1<=n <= 10^9).
 
Output
For each integer n, please print output the x in a single line, if x does not exit , print -1 instead.
 
SampleInput
2
2
3
 
SampleOutput
-1
1
 

抱歉!评论已关闭.