亲和数(因子和)

Problem Description

古希腊数学家毕达哥拉斯在自然数研究中发现,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 <= 600000 ;
 

 

Output
对于每个测试实例,如果A和B是亲和数的话输出YES,否则输出NO。
 

 

Sample Input
2 220 284 100 200
    
            比较快速的计算因子和,到根下。
       
 1 #include<iostream>
 2 #include<iomanip>
 3 //#include<bits/stdc++.h>
 4 #include<cstdio>
 5 #include<algorithm>
 6 #include<cmath>
 7 #define PI  3.14159265358979
 8 #define LL long long
 9 #define INF  10000001000
10 #define  eps   0.00000001
11 using namespace std;
12 int main()
13 {
14    int T;
15     cin>>T;
16     while(T--)
17     {
18         int a,b;
19         cin>>a>>b;
20         int sum1=0,sum2=0;
21         for(int i=2;i<=sqrt(a);++i)
22         {
23             if(a%i==0) {if(a/i==i) sum1+=i;
24             else {sum1+=i,sum1+=a/i;}}
25         }
26         for(int i=2;i<=sqrt(b);++i)
27         {
28               if(b%i==0) {if(b/i==i) sum2+=i;
29             else {sum2+=i,sum2+=b/i;}}
30         }
31         sum1++;sum2++;
32        // cout<<sum1<<" "<<sum2;return 0;
33         if(sum1==b&&sum2==a) cout<<"YES"<<endl;
34         else cout<<"NO"<<endl;
35 
36     }
37 
38 
39 }
View Code

 

转载于:https://www.cnblogs.com/Auroras/p/10803331.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值