- 亲和数
- 2015-08-02 21:14:25 @
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int qiu(int x)
{
int s=1,i,t;
t=int (sqrt(double(x+1)));
for(i=2;i<=t;i++)
{
if(x%i==0)
{
s=s+i+x/i;
}
}
if(t*t==x)
{
s=s-t;
}
return s;
}
int main()
{
int n,i,sb,A,B,ans=0,m;
scanf("%d%d",&n,&m);
if(n>m){int tt=n;n=m;m=tt;}
for(i=n;i<=m;i++)
{
A=i;
B=qiu(A);
sb=qiu(B);
if(sb==A)
{
ans++;
}
}
printf("%d\n",ans/2);
return 0;
}
4 条评论
-
online_wlq LV 8 @ 2018-07-28 20:27:20
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int a,b,sum,k,ans=0;
cin>>a>>b;
for(int i=a;i<=b;i++)
{
sum=1,k=1;
for(int j=2;j*j<=i;j++)
if(i%j==0)sum+=j+i/j;
for(int j=2;j*j<=sum;j++)
if(sum%j==0)k+=sum/j+j;
if(i==k&&i<sum)ans++;
}
cout<<ans;
return 0;
} -
2015-08-03 09:15:07@
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
int panduan(int x)
{
int s=0;
int t=int(sqrt(double(x+1)));
for(int i=1;i<=t;i++)
{
if(x%i==0)
{
s=s+i+x/i;
}
}
if(t*t==x)s-=t;
s-=x;
return s;
}
int main()
{
int i,j,n=0,x,y;
scanf("%d%d",&x,&y);
for(i=x;i<=y;i++)
{
int k=panduan(i);
if(panduan(k)==i&&k!=i&&i<k)
{
n++;
}
}
printf("%d\n",n);
return 0;
} -
2015-08-03 09:14:52@
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
int panduan(int x)
{
int s=0;
int t=int(sqrt(double(x+1)));
for(int i=1;i<=t;i++)
{
if(x%i==0)
{
s=s+i+x/i;
}
}
if(t*t==x)s-=t;
s-=x;
return s;
}
int main()
{
int i,j,n=0,x,y;
scanf("%d%d",&x,&y);
for(i=x;i<=y;i++)
{
int k=panduan(i);
if(panduan(k)==i&&k!=i&&i<k)
{
n++;
}
}
printf("%d\n",n);
return 0;
} -
2015-08-03 08:36:45@
a[100]={220,1184,2620,5020,6232,10744,12285,17296,63020,66928,67095,69615,79750,100485,122265,122368,141664,142310,171856,176272,185368,196724,280540,308620,319550,356408,437456,469028,503056,522405,600392,609928,624184,635624,643336,667964,726104,802725,879712,898216,947835,998104,1077890,1077890,1154450,1280565,1392368,1511930,1798875,2082464,4238984,5459176,6329416,7677248,9363584,10254970,13921528,16137628,50997596,52695376,56055872,56512610,56924192,58580540,59497888,63560025,63717615,66595130,66854710,67729064,67738268,68891992,71015260,71241830,72958556,73032872,74055952,74386305,74769345,75171808,75226888,78088504,78447010,79324875,80422335,82633005,83135650,84521745,84591405,86158220,87998470,88144630,89477984,90437150,91996816,93837808,95629904,95791430,96304845,97041735}
int n,m;
scanf("%d%d",&n,&m);
for(i=0;i<100;i++)
if(a[i]>=n&&a[i]<=m)s++;
printf("%d",s);
- 1