Saleh127

Spoj DIVSUM

Jul 6th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int sd(int n)
  4. {
  5. int l=sqrt(n);
  6. int ans=0,i;
  7. for(i=1;i<l;i++)
  8. {
  9. if(n%i==0)
  10. {
  11. ans+=i;
  12. ans+=(n/i);
  13. }
  14. }
  15. if(n%l==0)
  16. {
  17. if(l*l==n) ans+=l;
  18. else
  19. {
  20. ans+=l;
  21. ans+=(n/l);
  22. }
  23. }
  24. return ans;
  25. }
  26. int main()
  27. {
  28. int a,c,d,e,f,i,j,k,l;
  29. cin>>f;
  30. while(f--)
  31. {
  32. cin>>a;
  33. d=sd(a)-a;
  34. cout<<d<<endl;
  35. }
  36.  
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment