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