QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#657266 | #7735. Primitive Root | C10udz | TL | 328ms | 3812kb | C++17 | 1.5kb | 2024-10-19 14:28:36 | 2024-10-19 14:28:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for(int i = a; i <= n; i ++)
#define per(i, n, a) for(int i = n; i >= a; i --)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fopen(x) { freopen(#x".in", "r", stdin); freopen(#x".out", "w", stdout); }
#define fi first
#define se second
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<char> VC;
typedef vector<pair<int, int>> VP;
typedef pair<int, int> PII;
typedef long long ll;
typedef unsigned long long ull;
mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r) {return l + mrand() % (r - l + 1);}
const ll inf = 1e9 + 5, llf = 1e18 + 5;
///////////////////////////////////////////////////////////////////
void solve(){
ll p, m; cin >> p >> m;
ll ans = 0;
auto calcu = [&] (ll l, ll r) -> ll {
l = ceil(1.0 * (l - 1) / p), r = floor(1.0 * (r - 1) / p);
if(r < 0) return 0;
if(l < 0) l = 0;
cerr << l << " " << r << "\n";
return max(0ll, r - l + 1);
};
per(i, 60, 0) {
if(m >> i & 1) {
ll l = m >> i;
l --;
l ^= (p - 1) >> i;
l <<= i;
ll r = l + (1ll << i) - 1;
ans += calcu(l, r);
}
}
ans += calcu(m ^ (p - 1), m ^ (p - 1));
cout << ans << "\n";
}
signed main() {
IOS;
int T; cin >> T;
while(T --){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3672kb
input:
3 2 0 7 11 1145141 998244353
output:
1 2 872
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 236ms
memory: 3676kb
input:
47595 2 0 2 1 2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 2 26 2 27 2 28 2 29 2 30 2 31 2 32 2 33 2 34 2 35 2 36 2 37 2 38 2 39 2 40 2 41 2 42 2 43 2 44 2 45 2 46 2 47 2 48 2 49 2 50 2 51 2 52 2 53 2 54 2 55 2 56 2 57 2 58 2 59 2 60...
output:
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 52 53 53 ...
result:
ok 47595 lines
Test #3:
score: 0
Accepted
time: 328ms
memory: 3724kb
input:
100000 11 34 71 35 11 45 53 28 3 67 17 38 41 2 23 8 47 26 79 98 89 47 97 33 43 95 97 98 29 79 29 48 67 27 37 3 97 72 71 97 67 53 23 77 71 12 101 92 89 63 61 71 59 94 97 2 29 64 53 74 47 78 67 0 97 66 79 81 3 48 67 87 79 88 59 63 17 25 61 37 67 64 79 93 67 92 89 0 59 88 11 29 29 5 13 47 101 80 3 12 8...
output:
3 1 5 1 23 3 1 0 0 2 1 1 2 2 4 3 1 1 1 2 1 4 0 1 1 3 3 1 3 2 2 0 1 2 16 2 2 2 2 1 1 2 2 0 3 3 1 4 1 4 1 1 14 45 1 1 3 1 4 2 1 2 1 1 2 1 8 2 1 2 1 1 0 1 2 2 1 3 3 9 1 2 1 1 32 1 1 2 1 1 0 1 4 1 1 3 1 2 1 2 2 1 0 2 3 0 1 1 1 3 2 2 1 5 4 1 1 3 2 0 3 2 3 1 6 1 2 9 0 2 2 3 1 1 2 1 2 2 1 1 0 2 2 12 21 4 3...
result:
ok 100000 lines
Test #4:
score: 0
Accepted
time: 292ms
memory: 3672kb
input:
100000 29 83 47 14 29 56 2 29 17 35 67 31 3 24 97 39 17 5 59 16 53 51 29 51 67 72 53 14 79 54 11 35 83 56 89 11 5 70 67 42 89 65 7 40 41 45 79 13 7 26 5 51 5 49 47 46 19 2 89 74 47 27 71 37 37 39 83 86 7 86 71 15 29 94 19 17 101 56 23 3 59 95 97 73 11 15 29 66 23 23 23 51 53 95 11 95 61 0 97 14 73 5...
output:
4 0 3 15 2 1 8 1 1 1 1 3 2 1 1 3 1 1 15 1 1 6 2 0 4 10 10 1 0 1 0 1 2 2 13 1 4 1 1 0 3 1 2 3 2 2 3 9 0 1 1 2 4 0 1 1 2 1 11 2 1 2 3 1 1 1 3 3 1 1 2 1 1 1 1 1 5 8 1 4 9 0 3 1 14 2 1 2 2 1 6 3 1 5 1 1 3 1 2 10 1 2 4 2 1 1 1 1 1 1 4 3 1 5 1 1 2 1 1 1 2 1 6 2 1 0 7 0 1 2 2 4 2 1 1 2 3 1 3 1 1 1 3 1 6 3 ...
result:
ok 100000 lines
Test #5:
score: 0
Accepted
time: 292ms
memory: 3812kb
input:
100000 59 60 97 9 53 69 7 58 71 67 3 88 61 92 83 42 67 64 71 43 29 30 83 31 89 89 47 93 67 90 97 74 11 80 89 84 47 38 19 43 67 55 59 15 101 68 71 58 97 40 73 94 71 88 89 8 67 35 37 81 31 24 23 58 73 51 43 34 71 88 41 69 37 37 7 2 79 79 97 65 17 89 41 78 31 3 97 37 7 91 47 95 97 33 97 60 37 74 29 83 ...
output:
2 1 2 8 1 29 3 1 1 1 2 1 2 2 2 1 8 1 1 3 1 1 1 1 1 2 2 1 1 2 0 3 1 1 2 2 2 0 2 1 6 2 0 1 14 2 1 1 2 4 5 0 5 1 2 1 1 1 0 1 1 0 7 17 2 7 3 1 0 0 1 1 8 3 1 2 1 1 1 1 0 1 1 7 4 2 7 5 0 1 21 3 1 1 0 3 0 0 2 1 1 1 2 5 6 4 1 2 1 1 2 1 4 1 1 2 21 0 3 1 5 1 20 1 2 1 3 5 0 0 6 3 1 2 5 0 1 3 8 2 1 3 1 1 3 1 1 ...
result:
ok 100000 lines
Test #6:
score: -100
Time Limit Exceeded
input:
100000 1861 3528 2333 9090 2579 5653 8147 4315 1381 1926 1213 8598 7681 7742 5039 8270 7927 3661 2819 9458 7229 4213 683 8300 787 4660 7753 1678 7283 9943 6029 2737 5051 6439 9371 9827 1277 5268 2753 5913 5437 1537 2851 4021 1289 1807 6529 7605 7949 9316 8101 2770 6451 2437 2039 1348 1307 6586 9011 ...
output:
3 4 3 1 2 8 2 2 1 3 1 13 7 1 3 1 2 2 4 2 1 2 2 2 3 1 1 1 5 1 2 1 1 1 1 14 6 4 1 1 1 2 1 1 2 23 1 32 1 2 7 4 1 2 3 1 2 2 4 1 9 1 4 3 4 1 5 3 2 2 4 123 1 2 9 1 1 3 1 1 2 1 3 1 1 4 3 1 1 1 1 1 1 1 1 3 1 1 4 4 1 3 1 18 1 11 1 2 2 1 3 1 1 0 329 1 1 2 3 1 2 1 1 4 1 1 2 4 5 1 3 1 7 2 1 1 2 1 2 2 2 1 1 1 2 ...