QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#634454 | #9309. Graph | KafuuChinocpp | WA | 42ms | 9708kb | C++14 | 2.2kb | 2024-10-12 17:21:10 | 2024-10-12 17:21:10 |
Judging History
answer
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int max1 = 316227;
const int mod = 998244353;
long long n;
bool is_not_prime[max1 + 5];
int prime[max1 + 5], total;
void Get_Prime ()
{
for ( int i = 2; i <= max1; i ++ )
{
if ( !is_not_prime[i] )
prime[++total] = i;
for ( int j = 1; j <= total && i * prime[j] <= max1; j ++ )
{
is_not_prime[i * prime[j]] = true;
if ( !(i % prime[j]) )
break;
}
}
return;
}
long long w[max1 * 2 + 5], f[max1 * 2 + 5], cnt;
int id1[max1 + 5], id2[max1 + 5];
int Quick_Power ( int base, long long p )
{
int res = 1;
while ( p )
{
if ( p & 1 )
res = 1LL * res * base % mod;
p >>= 1;
base = 1LL * base * base % mod;
}
return res;
}
int Calc ( long long m )
{
if ( m == 1 || m == 2 )
return 1;
if ( m == 3 )
return 3;
int v1 = m <= max1 ? id1[m] : id2[n / m];
int v2 = m / 2 <= max1 ? id1[m / 2] : id2[n / (m / 2)];
long long c = f[v1] - f[v2];
return 1LL * Quick_Power(m, c) * ((m - c - 1) % mod) % mod;
}
int main ()
{
Get_Prime();
scanf("%lld", &n);
for ( long long L = 1, R; L <= n; L = R + 1 )
{
R = n / (n / L);
w[++cnt] = n / L;
f[cnt] = w[cnt] - 1;
if ( w[cnt] <= max1 )
id1[w[cnt]] = cnt;
else
id2[n / w[cnt]] = cnt;
}
for ( int i = 1; i <= total; i ++ )
{
if ( 1LL * prime[i] * prime[i] > n )
break;
for ( int j = 1; j <= cnt; j ++ )
{
if ( 1LL * prime[i] * prime[i] > w[j] )
break;
int v = w[j] / prime[i] <= max1 ? id1[w[j] / prime[i]] : id2[n / (w[j] / prime[i])];
f[j] = f[j] - f[v] + i - 1;
}
}
int ans = 1;
for ( long long L = 1, R; L <= n; L = R + 1 )
{
R = n / (n / L);
int val = Calc(n / L);
ans = 1LL * ans * Quick_Power(val, R - L + 1) % mod;
}
printf("%d\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6064kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 1ms
memory: 4120kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 2ms
memory: 4072kb
input:
123
output:
671840470
result:
ok answer is '671840470'
Test #4:
score: 0
Accepted
time: 1ms
memory: 4120kb
input:
233
output:
353738465
result:
ok answer is '353738465'
Test #5:
score: 0
Accepted
time: 1ms
memory: 4104kb
input:
5981
output:
970246821
result:
ok answer is '970246821'
Test #6:
score: 0
Accepted
time: 0ms
memory: 4200kb
input:
86422
output:
897815688
result:
ok answer is '897815688'
Test #7:
score: 0
Accepted
time: 2ms
memory: 4156kb
input:
145444
output:
189843901
result:
ok answer is '189843901'
Test #8:
score: 0
Accepted
time: 0ms
memory: 4344kb
input:
901000
output:
819449452
result:
ok answer is '819449452'
Test #9:
score: 0
Accepted
time: 2ms
memory: 4264kb
input:
1000000
output:
113573943
result:
ok answer is '113573943'
Test #10:
score: 0
Accepted
time: 0ms
memory: 5112kb
input:
23333333
output:
949849384
result:
ok answer is '949849384'
Test #11:
score: 0
Accepted
time: 5ms
memory: 5480kb
input:
102850434
output:
604886751
result:
ok answer is '604886751'
Test #12:
score: 0
Accepted
time: 12ms
memory: 7012kb
input:
998244353
output:
0
result:
ok answer is '0'
Test #13:
score: 0
Accepted
time: 16ms
memory: 7796kb
input:
1000000007
output:
318420284
result:
ok answer is '318420284'
Test #14:
score: 0
Accepted
time: 21ms
memory: 8136kb
input:
2147483547
output:
688759898
result:
ok answer is '688759898'
Test #15:
score: -100
Wrong Answer
time: 42ms
memory: 9708kb
input:
5120103302
output:
384994873
result:
wrong answer expected '116870489', found '384994873'