首页 > ACM题库 > HDU-杭电 > hdu 3542 ZaakDov is doing his math problem! 待解决[解题报告]C++
2014
11-05

hdu 3542 ZaakDov is doing his math problem! 待解决[解题报告]C++

ZaakDov is doing his math problem!

问题描述 :

Given an odd prime p.
You are to tell whether p can be written into form a^2+b^2 (0<a<=b),
and if p can be done, you are to determine a pair of a,b.

输入:

There will be up to 2*10^5 test cases.
An odd prime p (3<=p<2*10^9) in each line.
End with EOF.

输出:

There will be up to 2*10^5 test cases.
An odd prime p (3<=p<2*10^9) in each line.
End with EOF.

样例输入:

3
5
7
11
13
17
19
23
29

样例输出:

Illegal
Legal 1 2
Illegal
Illegal
Legal 2 3
Legal 1 4
Illegal
Illegal
Legal 2 5


  1. #include <cstdio>

    int main() {
    //answer must be odd
    int n, u, d;
    while(scanf("%d%d%d",&n,&u,&d)==3 && n>0) {
    if(n<=u) { puts("1"); continue; }
    n-=u; u-=d; n+=u-1; n/=u;
    n<<=1, ++n;
    printf("%dn",n);
    }
    return 0;
    }