Advertisement
yuawn

algo2017_week2_perfect_number

Oct 3rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int sum( int n ){
  5.     int sum = 0;
  6.     for( int i = 2 ; i <= sqrt( n ) ; i++ ){
  7.         if( !( n % i ) ) sum += i + n / i;
  8.     }
  9.     return sum + 1;
  10. }
  11.  
  12. int main(){
  13.     int t;
  14.     cin >> t;
  15.     while( t-- ){
  16.         int n;
  17.         cin >> n;
  18.         if( n == sum( n ) ) cout << n << ' ';
  19.     }
  20.     puts("");
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement