Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. int perfect(int x)
  5. {
  6. int i,s=0;
  7. for(i=1;i<=x;i++)
  8.  
  9. if(x%i==0)
  10. s++;
  11. if(2*x==s)
  12. return 1;
  13. else return 0;
  14.  
  15. }
  16. int main()
  17. {
  18. ifstream f("perfect.in");
  19. int n,i=1,max=0,poz;
  20. while(f>>n)
  21. {
  22. if(perfect(n)==1&&max<n)
  23. {
  24. max=n;
  25. poz=i;
  26. }
  27. i++;
  28. }
  29. if(max==0 )
  30. cout<<"imposibil";
  31. else cout<<max<<" "<<poz;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement