QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#634421 | #9309. Graph | KafuuChinocpp | RE | 24ms | 8124kb | C++14 | 2.2kb | 2024-10-12 17:17:28 | 2024-10-12 17:17:28 |
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 ( int 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)];
int c = f[v1] - f[v2];
return 1LL * Quick_Power(m, c) * (m - c - 1) % 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 ( int 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;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4008kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 1ms
memory: 4064kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 2ms
memory: 6128kb
input:
123
output:
671840470
result:
ok answer is '671840470'
Test #4:
score: 0
Accepted
time: 1ms
memory: 4108kb
input:
233
output:
353738465
result:
ok answer is '353738465'
Test #5:
score: 0
Accepted
time: 2ms
memory: 4104kb
input:
5981
output:
970246821
result:
ok answer is '970246821'
Test #6:
score: 0
Accepted
time: 1ms
memory: 4160kb
input:
86422
output:
897815688
result:
ok answer is '897815688'
Test #7:
score: 0
Accepted
time: 1ms
memory: 4188kb
input:
145444
output:
189843901
result:
ok answer is '189843901'
Test #8:
score: 0
Accepted
time: 2ms
memory: 6140kb
input:
901000
output:
819449452
result:
ok answer is '819449452'
Test #9:
score: 0
Accepted
time: 1ms
memory: 4360kb
input:
1000000
output:
113573943
result:
ok answer is '113573943'
Test #10:
score: 0
Accepted
time: 3ms
memory: 5112kb
input:
23333333
output:
949849384
result:
ok answer is '949849384'
Test #11:
score: 0
Accepted
time: 2ms
memory: 7508kb
input:
102850434
output:
604886751
result:
ok answer is '604886751'
Test #12:
score: 0
Accepted
time: 15ms
memory: 6616kb
input:
998244353
output:
0
result:
ok answer is '0'
Test #13:
score: 0
Accepted
time: 11ms
memory: 6664kb
input:
1000000007
output:
318420284
result:
ok answer is '318420284'
Test #14:
score: 0
Accepted
time: 24ms
memory: 8124kb
input:
2147483547
output:
688759898
result:
ok answer is '688759898'
Test #15:
score: -100
Runtime Error
input:
5120103302