Advertisement
halexandru11

atestat_5.cpp

Nov 23rd, 2020
67
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. // determina suma divizorilor lui x
  7. // neconsiderandu-se numarul in sine
  8. unsigned int suma_div(unsigned int x) {
  9.     unsigned int suma = 1;
  10.     for(unsigned int div = 2; div <= x/2; ++div) {
  11.         if(x%div == 0) {
  12.             suma += div;
  13.         }
  14.     }
  15.     return suma;
  16. }
  17.  
  18. int main() {
  19.     ifstream fin("numere.txt");
  20.  
  21.     unsigned int x, y;
  22.     // citesc cat timp in fisier exista numere
  23.     while(fin >> x >> y) {
  24.         // daca (x, y) respecta conditia ceruta le afisez
  25.         if(suma_div(x) == y+1 && suma_div(y) == x+1) {
  26.             cout << x << " " << y << "\n";
  27.         }
  28.     }
  29. }
  30.  
Advertisement
RAW Paste Data Copied
Advertisement