Advertisement
MeehoweCK

Untitled

May 1st, 2023
889
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // wersja "profesjonalna":
  6. unsigned suma_dzielnikow_wlasciwych(unsigned n)
  7. {
  8.     if (n == 1)
  9.         return 0;
  10.     unsigned suma = 1;
  11.     unsigned i;
  12.  
  13.     for(i = 2; i * i < n; ++i)
  14.         if (n % i == 0)
  15.             suma += (i + n / i);
  16.  
  17.     if (i * i == n)
  18.         suma += i;
  19.  
  20.     return suma;
  21. }
  22.  
  23. int main()
  24. {
  25.     cout << suma_dzielnikow_wlasciwych(999999999) << endl;
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement