TOJ1154. A Mathematical Curiosity

http://acm.tju.edu.cn/toj/showp1154.html

这道题不难,但是WA了,看网上的介绍说是不能当m、n同时为0的时候退出,而是n=0的时候退出…

不知道是为什么,改了之后竟然AC了… 很奇怪…

https://blog.csdn.net/u010643814/article/details/38562603

代码:

#include 
#include 

int main(){
    int m, n, result;
    int count = 0;
    while(scanf("%d %d", &n, &m) && n){
        result = 0;
        count++;
        for(int a = 1; a < n; a++){
            for(int b = a+1; b < n; b++){
                if((a*a+b*b+m)%(a*b)==0){
                    result++;
                }
            }
        }
        printf("Case %d: %d\n", count, result);
    }
    return 0;
}

 

你可能感兴趣的:(ACM刷题)