Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int suma_dzielnikow_wlasciwych(int n)
- {
- if (n == 1)
- return 0;
- int suma = 1;
- int i;
- for (i = 2; i*i < n; i++)
- {
- if(n % i == 0)
- suma += (i + n/i); //cout << ' ' << i << ' ' << n/i;
- }
- if(i*i == n)
- suma += i; //cout << ' ' << i;
- return suma;
- }
- void zaprzyjaznione(int n)
- {
- for(int i = 1; i < n; ++i)
- {
- int b = suma_dzielnikow_wlasciwych(i);
- if(b > i && b < n)
- if(i == suma_dzielnikow_wlasciwych(b))
- cout << i << '\t' << b << endl;
- }
- }
- int main()
- {
- int n;
- cin >> n;
- cout << "Liczby zaprzyjaznione mniejsze od " << n << ":\n";
- zaprzyjaznione(n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement