fork(3) download
  1. int solve (int n, int r) {
  2. vector<int> p;
  3. for (int i=2; i*i<=n; ++i)
  4. if (n % i == 0) {
  5. p.push_back (i);
  6. while (n % i == 0)
  7. n /= i;
  8. }
  9. if (n > 1)
  10. p.push_back (n);
  11.  
  12. int sum = 0;
  13. for (int msk=1; msk<(1<<p.size()); ++msk) {
  14. int mult = 1,
  15. bits = 0;
  16. for (int i=0; i<(int)p.size(); ++i)
  17. if (msk & (1<<i)) {
  18. ++bits;
  19. mult *= p[i];
  20. }
  21.  
  22. int cur = r / mult;
  23. if (bits % 2 == 1)
  24. sum += cur;
  25. else
  26. sum -= cur;
  27. }
  28.  
  29. return r - sum;
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int solve(int, int)':
prog.cpp:2:2: error: 'vector' was not declared in this scope
  vector<int> p;
  ^
prog.cpp:2:9: error: expected primary-expression before 'int'
  vector<int> p;
         ^
prog.cpp:5:2: error: 'p' was not declared in this scope
  p.push_back (i);
  ^
prog.cpp:10:2: error: 'p' was not declared in this scope
  p.push_back (n);
  ^
prog.cpp:13:26: error: 'p' was not declared in this scope
  for (int msk=1; msk<(1<<p.size()); ++msk) {
                          ^
stdout
Standard output is empty