Advertisement
Josif_tepe

Untitled

Mar 10th, 2023
748
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. int main() {
  7.     int b, j;
  8.     cin >> b >> j;
  9.    
  10.     map<int, int> m;
  11.    
  12.     for(int i = 1; i <= sqrt(b); i++) {
  13.         if(b % i == 0) {
  14.             m[i]++;
  15.            
  16.             if(i != b / i) {
  17.                 m[b / i]++;
  18.             }
  19.         }
  20.     }
  21.     int result = 0;
  22.     for(int i = 1; i <= sqrt(j); i++) {
  23.         if(j % i == 0) {
  24.             m[i]++;
  25.            
  26.             if(m[i] == 2) {
  27.                 result++;
  28.             }
  29.            
  30.             if(i != j / i) {
  31.                 m[j / i]++;
  32.                 if(m[j / i] == 2) {
  33.                     result++;
  34.                 }
  35.             }
  36.            
  37.         }
  38.     }
  39.     cout << result << endl;
  40.     return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement