HDOJ 1017 (水题)

来源:互联网 发布:淘宝首页轮播大图代码 编辑:程序博客网 时间:2024/06/09 09:05
给定n,m要求满足(x^2+y^2+m)/ab为整数,然后0<a<b<n。求有多少组a,b;n的范围太小了。肯定是个水题没得跑了。不过要注意下输出形式就是了。
#include <iostream>using namespace std;int main(){    ios::sync_with_stdio(false);cin.tie(0);    int N;    cin>>N;    while(N--){        int n,m;        int i = 1;         while(cin>>n>>m){            if(m==0 && n==0) break;            int ans=0;            for(int a = 1;a < n;a ++)                 for(int b = a+1;b < n;b ++){                    int res=(a*a+b*b+m)%(a*b);                    if(res == 0) ans++;                }                cout<<"Case "<<i++<<": "<<ans<<endl;        }        if(N!=0)            cout<<endl;    }    return 0;}
原创粉丝点击