fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool ktrsnt(int x){
  5. if(x < 2) return false;
  6. for(int i = 2; i <= sqrt(x); i++){
  7. if(x % i == 0){
  8. return false;
  9. }
  10. }
  11. return true;
  12. }
  13. int main()
  14. {
  15. ios_base::sync_with_stdio(0);
  16. cout.tie(0);cin.tie(0);
  17.  
  18. int n, m;
  19. cin >> n >> m;
  20. int tong = 0;
  21. for(int i = 1; i <= sqrt(m); i++){
  22. if(m % i == 0){
  23. int a = i;
  24. int b = m / i;
  25.  
  26. if(a == b){
  27. if(n % a == 0 && ktrsnt(a)) tong += a;
  28. }
  29. else{
  30. if(n % a == 0 && ktrsnt(a)) tong += a;
  31. if(n % b == 0 && ktrsnt(b)) tong += b;
  32. }
  33. }
  34. }
  35. cout << tong;
  36.  
  37. }
Success #stdin #stdout 0.01s 5328KB
stdin
Standard input is empty
stdout
1744