O(sqrt(n))枚举约数,根据定义暴力判断友好数。

 1 #include<cstdio>
 2 #include<cmath>
 3 using namespace std;
 4 int n; int limit;
 5 int main()
 6 {
 7     scanf("%d",&n);
 8     for(;;n++)
 9       {
10           limit=sqrt(n); int tot=1;
11           if(limit*limit==n) tot+=limit;
12           for(int i=2;i<limit;i++) if(n%i==0) tot+=(i+n/i);
13           limit=sqrt(tot); int tot2=1;
14           if(limit*limit==tot) tot2+=limit;
15           for(int i=2;i<limit;i++) if(tot%i==0) tot2+=(i+tot/i);
16           if(tot2==n)
17           {
18               printf("%d %d\n",n,tot);
19               break;
20           }
21       }
22     return 0;
23 }

 

相关文章:

  • 2022-12-23
  • 2022-02-14
  • 2021-06-02
  • 2022-03-06
  • 2022-12-23
  • 2022-02-04
  • 2021-05-21
  • 2022-03-09
猜你喜欢
  • 2021-11-26
  • 2022-12-23
  • 2021-07-26
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
相关资源
相似解决方案