2 solutions

  • 0
    @ 2022-5-29 16:59:00
    #include <iostream>
    using namespace std;
    int perfectnum(int x)
    {
    	int sum=0;
    	for(int i=1;i<x;i++)
    	{
    		if(x%i==0){
    			sum+=i;
    		}
    	}
    	return sum;
    }
    int main()
    {
    	int m,n;
    	cin>>m>>n;
    	for(int i=m;i<=n;i++)
    	{
    		if(perfectnum(i)==i)
    		{
    			cout<<i<<' ';
    		}
    	}
    	return 0;
    }
    
    • 0
      @ 2022-5-29 16:06:58
      #include <bits/stdc++.h>
      using namespace std;
      #define accelerate ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
      #define endl "\n";
      #define mod 12345
      #define ll long long
      #define PII pair<int,int>
      #define INF 0x3f3f3f3f
      const int N=1e5+10;
      ll n,m,k,x,y,T;
      ll a[N];
      ll pre[N];
      bool f(int x){
      	int sum=0;
      	for(int i=1;i<x;i++){
      		sum+=x%i==0?i:0;
      	}
      	return (x==sum);
      }
      int main(){
      	accelerate;
      	cin>>n>>m;
      	for(int i=n;i<=m;i++){
      		if(f(i)) cout<<i<<" ";
      	}
      	return 0;
      }
      
      • 1

      【入门】输出m和n范围内的完全数(完美数)

      Information

      ID
      476
      Time
      1000ms
      Memory
      16MiB
      Difficulty
      8
      Tags
      # Submissions
      11
      Accepted
      7
      Uploaded By