QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#182649 | #5738. Square Sum | ucup-team1209# | WA | 36ms | 3556kb | C++20 | 2.5kb | 2023-09-18 12:09:12 | 2023-09-18 12:09:13 |
Judging History
answer
#include<bits/stdc++.h>
using std::cin;
using std::cout;
using u64 = unsigned long long;
using ll = long long;
int a[1 << 20];
int pow(int a, int b, int mod) {
int ans = 1;
for(;b;b >>= 1, a = (u64) a * a % mod) if(b & 1)
ans = (u64) ans * a % mod;
return ans;
}
int chkp(int p) {
return pow(p - 1, p / 2, p);
}
std::vector<int> table(int m) {
std::vector<int> res(m);
for(int i = 0;i < m;++i)
for(int j = 0;j < m;++j)
++ res[(i * i + j * j) % m];
return res;
}
ll calc2(int c, int pos) {
if(c == 1) return 2;
if(pos == 0) return 1 << c;
if(pos == 1) return 2 << c;
int d = c - 1;
for(;1 << d > pos;) -- d;
if(pos == 1 << d) {
if(d == c - 1) return 1 << c;
return 2 << c;
}
if(pos == 3 << (d - 1)) return 0;
return calc2(c, pos - (1 << d));
}
ll calc(int p, int c, int pos) {
ll base = 0;
int state = 0;
if(chkp(p) == 1) {
base = p - 1;
state = 1;
} else {
base = p + 1;
}
for(int i = 1;i < c;++i) {
base *= p;
}
if(pos) {
int cnt = 1;
for(;pos % p == 0;) {
pos /= p;
cnt += 1;
}
if(!state) {
return cnt % 2 * base;
}
return cnt * base;
} else {
std::vector<int> cnt(c + 1);
cnt[c] = 1;
for(int i = c - 1;i >= 0;--i) {
cnt[i] = cnt[i + 1] * p;
}
for(int i = 0;i < c;++i) {
cnt[i] -= cnt[i + 1];
}
ll all = 1;
for(int i = 0;i < c;++i) {
all *= p;
all *= p;
}
for(int i = 0;i < c;++i) {
if(state) {
all -= (ll) cnt[i] * (i + 1) * base;
} else {
all -= (ll) (i + 1) % 2 * cnt[i] * base;
}
}
return all;
}
}
void debug() {
int m = 0;
for(int m = 0;m <= 13;++m) {
auto res = table(1 << m);
for(int i = 0;i < 1 << m;++i) {
assert(res[i] == calc2(m, i));
}
}
}
int main() {
std::ios::sync_with_stdio(false), cin.tie(0);
//debug();
//return 0;
int t;
int m, n;
cin >> m >> n;
ll ans = 1;
int c_2 = 0;
std::vector<std::array<int, 3>> ps;
for(int i = 2;i * i <= m;++i) {
if(m % i == 0) {
int c = 0;
int mul = 1;
while(m % i == 0) {
m /= i;
mul *= i;
++ c;
}
if(i == 2) {
c_2 = c;
// ans *= calc2(c, n % mul);
} else {
ps.push_back({i, c, mul});
// ans *= calc(i, c, n % mul);
}
}
}
if(m > 1) ps.push_back({m, 1, m});
for(int i = 0;i < n;++i) {
int z;
cin >> z;
ll ans = calc2(c_2, z % (1 << c_2));
for(auto a : ps) {
ans *= calc(a[0], a[1], z % a[2]);
}
cout << ans << ' ';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3428kb
input:
3 3 0 1 2
output:
1 4 4
result:
ok 3 number(s): "1 4 4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
4 4 0 1 2 3
output:
4 8 4 0
result:
ok 4 number(s): "4 8 4 0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
5 1 3
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: 0
Accepted
time: 21ms
memory: 3440kb
input:
735134400 100000 4 4 1 2 3 4 4 4 5 4 3 4 1 1 1 1 2 0 1 4 4 5 4 1 0 0 1 3 0 4 0 5 3 0 3 0 5 4 0 0 3 2 5 3 2 4 3 4 2 1 3 3 2 2 2 3 1 0 1 2 3 4 3 5 4 4 0 1 5 2 2 3 3 2 4 3 5 5 1 3 1 1 4 3 4 3 4 5 2 4 1 3 2 0 5 0 0 5 5 1 2 0 3 4 0 4 1 0 1 4 5 5 3 1 3 0 3 5 0 4 2 0 4 0 0 0 4 0 2 2 2 4 5 3 0 2 0 4 1 4 1 2...
output:
1698693120 1698693120 1698693120 1698693120 0 1698693120 1698693120 1698693120 3397386240 1698693120 0 1698693120 1698693120 1698693120 1698693120 1698693120 1698693120 30888000 1698693120 1698693120 1698693120 3397386240 1698693120 1698693120 30888000 30888000 1698693120 0 30888000 1698693120 30888...
result:
ok 100000 numbers
Test #5:
score: 0
Accepted
time: 27ms
memory: 3508kb
input:
735134400 100000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 308...
result:
ok 100000 numbers
Test #6:
score: 0
Accepted
time: 9ms
memory: 3508kb
input:
536870912 100000 1 0 2 4 3 1 3 5 5 1 0 2 1 1 1 0 4 2 4 1 3 2 1 4 3 2 1 2 4 0 4 2 2 1 5 4 1 5 3 0 2 3 4 4 3 4 2 1 2 5 2 1 5 3 1 3 3 0 0 4 3 4 0 4 2 0 5 2 0 3 1 0 0 1 5 5 5 5 5 1 5 3 1 2 4 1 3 3 2 0 2 0 5 1 0 2 1 2 5 2 5 4 4 3 0 3 3 5 4 3 3 2 0 2 1 2 0 1 4 1 1 4 2 4 1 2 4 4 4 2 3 4 5 5 5 4 3 5 5 2 1 5...
output:
1073741824 536870912 1073741824 1073741824 0 1073741824 0 1073741824 1073741824 1073741824 536870912 1073741824 1073741824 1073741824 1073741824 536870912 1073741824 1073741824 1073741824 1073741824 0 1073741824 1073741824 1073741824 0 1073741824 1073741824 1073741824 1073741824 536870912 1073741824...
result:
ok 100000 numbers
Test #7:
score: 0
Accepted
time: 4ms
memory: 3492kb
input:
536870912 100000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 ...
result:
ok 100000 numbers
Test #8:
score: 0
Accepted
time: 11ms
memory: 3508kb
input:
536870912 100000 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268...
output:
536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 ...
result:
ok 100000 numbers
Test #9:
score: 0
Accepted
time: 22ms
memory: 3436kb
input:
536870912 100000 504070704 500101584 484480320 75189632 133364432 237444928 506874208 477655312 261146688 36394912 312952944 260479168 77969872 60413040 249853392 288067360 129948656 311385424 444949024 339508400 62885472 368704208 379750624 528964784 158077280 415604832 393291776 342918080 20621644...
output:
0 1073741824 1073741824 0 1073741824 1073741824 0 1073741824 1073741824 1073741824 0 0 1073741824 0 1073741824 1073741824 0 1073741824 1073741824 0 0 1073741824 0 0 0 0 1073741824 0 1073741824 0 0 1073741824 1073741824 1073741824 0 0 0 1073741824 0 0 0 0 0 0 1073741824 1073741824 0 1073741824 0 0 0 ...
result:
ok 100000 numbers
Test #10:
score: 0
Accepted
time: 14ms
memory: 3432kb
input:
536870912 100000 485294080 49414144 71499776 405143552 295436288 188612608 153288704 515768320 24248320 34471936 173539328 437387264 413663232 516947968 112263168 442826752 346488832 22151168 244514816 194510848 259260416 115015680 21757952 496828416 79429632 518979584 65011712 74317824 439812096 44...
output:
1073741824 1073741824 0 0 0 0 0 0 1073741824 0 0 1073741824 1073741824 1073741824 1073741824 1073741824 0 1073741824 0 0 1073741824 0 0 1073741824 0 0 0 0 0 1073741824 1073741824 0 0 1073741824 0 0 1073741824 1073741824 1073741824 0 1073741824 1073741824 1073741824 1073741824 0 1073741824 0 0 0 1073...
result:
ok 100000 numbers
Test #11:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
536870912 100000 0 268435456 0 0 268435456 268435456 0 0 0 0 268435456 0 268435456 0 268435456 0 0 0 0 0 268435456 268435456 268435456 268435456 0 0 268435456 268435456 268435456 0 268435456 268435456 0 268435456 0 268435456 0 0 268435456 0 0 0 268435456 268435456 0 268435456 268435456 268435456 0 2...
output:
536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 ...
result:
ok 100000 numbers
Test #12:
score: 0
Accepted
time: 36ms
memory: 3544kb
input:
779796616 100000 495020978 289673094 752654486 745889165 186463032 629831042 568084109 351140037 633863589 766446110 731514155 674603390 119159255 209998056 365491910 488229083 674872263 239261773 726348242 127803836 478298775 449657268 316649799 497847195 529645573 633328344 385144015 422155171 520...
output:
1569924096 0 0 1569924096 784962048 1569924096 1569924096 1569924096 1569924096 0 0 0 0 784962048 0 0 0 1569924096 1569924096 784962048 0 784962048 0 0 1569924096 784962048 0 0 784962048 0 1569924096 0 0 1569924096 0 0 1569924096 0 1569924096 1569924096 0 0 784962048 1569924096 784962048 784962048 0...
result:
ok 100000 numbers
Test #13:
score: 0
Accepted
time: 29ms
memory: 3436kb
input:
448340770 100000 17590207 378448283 377356435 142317962 32832284 283362954 431249178 350392871 210493301 353126480 88048955 133187907 155481936 36161241 120732436 163213003 410911210 27608106 348596232 178846917 22097057 75219456 295899274 238130211 383793986 278864287 345593615 417444550 409017940 ...
output:
358988288 358988288 807723648 358988288 358988288 358988288 358988288 358988288 358988288 807723648 807723648 358988288 358988288 358988288 358988288 358988288 807723648 358988288 358988288 358988288 358988288 358988288 358988288 358988288 358988288 358988288 807723648 807723648 807723648 807723648 ...
result:
ok 100000 numbers
Test #14:
score: 0
Accepted
time: 26ms
memory: 3452kb
input:
266069635 100000 146486161 131831810 57279849 256487214 256048395 50362550 260854940 241073971 32811964 107121487 261768591 182834801 159474905 43026229 19974995 164881566 246287652 239486995 67200667 74910586 221718783 237592156 221561959 202289915 19119390 113997936 191068379 75123564 133679363 16...
output:
404490240 441262080 196116480 8171520 898283520 441262080 441262080 8171520 196116480 0 196116480 196116480 441262080 196116480 441262080 196116480 0 441262080 196116480 8171520 408576000 196116480 196116480 441262080 910103040 17024000 196116480 196116480 196116480 441262080 196116480 196116480 196...
result:
ok 100000 numbers
Test #15:
score: 0
Accepted
time: 8ms
memory: 3512kb
input:
1 100000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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