打卡14

3.1完数

 

#include<bits/stdc++.h>
using namespace std;
int n;

int f(int x)
{
int sum=0;
for(int i=2;i<n/i;i++)//可以缩短时间复杂度
{
if(x%i==0)sum+=i;
}
return sum;
}

int main()
{
int l,r;
cin>>l>>r;
for(int i=l;i<=r;i++)
{
if(i==f(i))n++;//如果因子和与数相等就加1
}
cout<<n<<endl;
}

posted on 2023-04-27 12:36  临江柔  阅读(10)  评论(0编辑  收藏  举报