Submit: 294 Solved: 127
[Submit][Status][Web Board]
Description
如果a的因子和等于b,b的因子和等于a,且a≠b,则称a,b为亲密数对。比如220的所有真约数(即不是自身的约数)之和为: 1+2+4+5+10+11+20+22+44+55+110=284。 284的所有真约数和为: 1+2+4+71+142=220。你的任务就编写一个程序,判断给定的两个数是否是亲和数
Input
输入数据第一行包含一个数M,接下有M行,每行一个实例,包含两个整数A,B; 其中 0≤A,B≤99999。
Output
对于每个测试实例,如果A和B是亲和数的话输出YES,否则输出NO。
Sample Input
2 220 284 100 200
Sample Output
YES NO
#include<iostream> using namespace std; int main() { int i,n,m,s,sn,l,m1; cin>>n; for(i=0;i<n;i++) { sn=0; l=0; cin>>m>>m1; for(s=1;s<m;s++) if(m%s==0) sn=sn+s; for(s=1;s<m1;s++) if(m1%s==0) l=l+s; if(m==l&&sn==m1) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }