QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#468090 | #3799. It's Surely Complex | PetroTarnavskyi# | TL | 0ms | 3824kb | C++20 | 2.6kb | 2024-07-08 19:19:10 | 2024-07-08 19:19:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
int p;
void updAdd(int& a, int b)
{
a += b;
if (a >= p)
a -= p;
}
void updSub(int& a, int b)
{
a -= b;
if (a < 0)
a += p;
}
int mult(int a, int b)
{
return (LL)a * b % p;
}
complex<LL> mult(complex<LL> a, complex<LL> b)
{
a *= b;
a = {(a.real() % p + p) % p, (a.imag() % p + p) % p};
return a;
}
complex<LL> binpow(complex<LL> a, LL n)
{
complex<LL> res = {1, 0};
while (n)
{
if (n & 1)
res = mult(res, a);
a = mult(a, a);
n /= 2;
}
return res;
}
VI mult(VI a, VI b)
{
VI c(SZ(a) + SZ(b) - 1);
FOR(i, 0, SZ(a))
FOR(j, 0, SZ(b))
updAdd(c[i + j], mult(a[i], b[j]));
return c;
}
pair<VI, VI> splitRealImag(int k, const VI& a)
{
assert(SZ(a) == k + 1);
VI resReal(k + 1), resImag(k + 1);
FOR(i, 0, k + 1)
{
int r = (k - i) % 4;
if (r == 0)
{
updAdd(resReal[i], a[i]);
}
else if (r == 1)
{
updAdd(resImag[i], a[i]);
}
else if (r == 2)
{
updSub(resReal[i], a[i]);
}
else
{
updSub(resImag[i], a[i]);
}
}
return {resReal, resImag};
}
VI multipointEval(const VI& a, const VI& xs)
{
VI res;
for (int x : xs)
{
int y = 0, pw = 1;
for (int ai : a)
{
updAdd(y, mult(ai, pw));
pw = mult(pw, x);
}
res.PB(y);
}
return res;
}
vector<complex<LL>> f(int k)
{
VI pol = {1};
FOR(j, 0, k)
pol = mult(pol, {j, 1});
auto [polReal, polImag] = splitRealImag(k, pol);
VI xs(p);
iota(ALL(xs), 0);
VI ysReal = multipointEval(polReal, xs);
VI ysImag = multipointEval(polImag, xs);
vector<complex<LL>> res(p);
FOR(j, 0, p)
res[j] = {ysReal[j], ysImag[j]};
return res;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
LL n;
cin >> p >> n;
vector<complex<LL>> f1 = f(p), f2 = f(n % p + 1);
complex<LL> ans = {1, 0};
FOR(j, 1, p)
ans = mult(ans, complex<LL>(0, j));
ans = binpow(ans, n / p);
FOR(j, 1, n % p + 1)
{
ans = mult(ans, complex<LL>(0, j));
}
ans = binpow(ans, n / p + 1);
FOR(x, 1, p)
{
if (x > n)
break;
ans = mult(ans, binpow(mult(binpow(f1[x], n / p), f2[x]), (n - x) / p + 1));
}
cout << ans.real() << " " << ans.imag() << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
input:
2 1
output:
1 1
result:
ok single line: '1 1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
2 2
output:
1 1
result:
ok single line: '1 1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
2 3
output:
0 0
result:
ok single line: '0 0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
2 4
output:
0 0
result:
ok single line: '0 0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
3 1
output:
2 1
result:
ok single line: '2 1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
3 2
output:
2 0
result:
ok single line: '2 0'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
3 3
output:
1 0
result:
ok single line: '1 0'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
3 4
output:
1 1
result:
ok single line: '1 1'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
3 5
output:
1 0
result:
ok single line: '1 0'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
3 6
output:
1 0
result:
ok single line: '1 0'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
5 1
output:
4 1
result:
ok single line: '4 1'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
5 2
output:
0 0
result:
ok single line: '0 0'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
5 3
output:
0 0
result:
ok single line: '0 0'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
5 4
output:
0 0
result:
ok single line: '0 0'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
5 5
output:
0 0
result:
ok single line: '0 0'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
5 6
output:
0 0
result:
ok single line: '0 0'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
5 7
output:
0 0
result:
ok single line: '0 0'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
5 8
output:
0 0
result:
ok single line: '0 0'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
5 9
output:
0 0
result:
ok single line: '0 0'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
5 10
output:
0 0
result:
ok single line: '0 0'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
7 1
output:
6 1
result:
ok single line: '6 1'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3752kb
input:
7 2
output:
3 0
result:
ok single line: '3 0'
Test #23:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
7 3
output:
2 5
result:
ok single line: '2 5'
Test #24:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
7 4
output:
1 0
result:
ok single line: '1 0'
Test #25:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
7 5
output:
5 2
result:
ok single line: '5 2'
Test #26:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
7 6
output:
6 0
result:
ok single line: '6 0'
Test #27:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
7 7
output:
1 0
result:
ok single line: '1 0'
Test #28:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
7 8
output:
4 4
result:
ok single line: '4 4'
Test #29:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
7 9
output:
4 0
result:
ok single line: '4 0'
Test #30:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
7 10
output:
2 2
result:
ok single line: '2 2'
Test #31:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
7 11
output:
1 0
result:
ok single line: '1 0'
Test #32:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
7 12
output:
4 4
result:
ok single line: '4 4'
Test #33:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
7 13
output:
1 0
result:
ok single line: '1 0'
Test #34:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
7 14
output:
1 0
result:
ok single line: '1 0'
Test #35:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
2 1000000000000000000
output:
0 0
result:
ok single line: '0 0'
Test #36:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
3 1000000000000000000
output:
1 1
result:
ok single line: '1 1'
Test #37:
score: -100
Time Limit Exceeded
input:
499979 1000000000000000000