fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. ll p, n;
  8. unordered_set<ll> marked;
  9. marked.insert(0);
  10.  
  11. cin >> p >> n;
  12.  
  13. ll sum = 0;
  14. for(int i = 1; i <= min(p * 2, n); i++) {
  15. sum = (sum + i) % p;
  16. marked.insert(sum);
  17. }
  18.  
  19. cout << marked.size() << endl;
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0s 15240KB
stdin
8 1000000000000000000
stdout
8