QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#876561 | #9309. Graph | Hygebra | AC ✓ | 1535ms | 592076kb | C++14 | 3.3kb | 2025-01-31 00:01:54 | 2025-01-31 00:01:55 |
Judging History
answer
//
// Created by Yang Hang on 2025/1/29.
//
#include <cstdio>
#include <cmath>
#include "vector"
using namespace std;
const int mod=998244353;
const int N=4000005;
int fact[N],ifact[N];
long long n;
inline int binom(int n,int m) {
if (m>n || n<0 || m<0) return 0;
return 1ll*fact[n]*ifact[m]%mod*ifact[n-m]%mod;
}
long long ksm(long long a,long long x) {
long long s=1;
while (x) {
if (x&1) s=1ll*s*a%mod;
a=1ll*a*a%mod;x>>=1;
}
return s;
}
const int INF = 2e9;
const long long INFLL = 4e18;
const int small_lim = 1e6+1;
const int big_lim = 1e5+1;
long long primes_till_i[small_lim];
long long primes_till_bigger_i[big_lim];
vector<long long> sieved_primes[small_lim];
vector<long long> sieved_primes_big[big_lim];
vector<long long> prime;
vector<int> lpf(small_lim);
void get(){
long long pw;
for(int i = 2; i < small_lim; i++){
if(! lpf[i]){
prime.push_back(i);
lpf[i] = i;
}
for(int j : prime){
if((j > lpf[i]) || (j*i >= small_lim)) break;
lpf[j*i] = j;
}
}
for(int i = 2; i < small_lim; i++){
primes_till_i[i] = primes_till_i[i-1] + (lpf[i] == i);
}
}
long long count_primes(long long x, int ind){
if(ind < 0) return x - 1;
if(1ll*prime[ind]*prime[ind] > x){
if(x < small_lim) return primes_till_i[x];
if(primes_till_bigger_i[n / x]) return primes_till_bigger_i[n / x];
int l = -1, r = ind;
while(r-l > 1){
int mid = (l+r)>>1;
if(1ll*prime[mid]*prime[mid] > x) r = mid;
else l = mid;
}
return primes_till_bigger_i[n / x] = count_primes(x, l);
}
int sz;
if(x < small_lim) sz = sieved_primes[x].size();
else sz = sieved_primes_big[n / x].size();
long long ans;
if(sz <= ind){
ans = count_primes(x, ind - 1);
ans -= count_primes(x / prime[ind], ind - 1);
ans += ind;
if(x < small_lim) sieved_primes[x].push_back(ans);
else sieved_primes_big[n / x].push_back(ans);
}
if(x < small_lim) return sieved_primes[x][ind];
else return sieved_primes_big[n / x][ind];
}
long long count_primes(long long x){
//printf("x = %lld\n",prime.size()-1);
if(x < small_lim) return primes_till_i[x];
if(primes_till_bigger_i[n/x]) return primes_till_bigger_i[n/x];
//puts("c");
return count_primes(x,prime.size()-1);
}
int main()
{
get();
//puts("c");
/* for (int i=0;i<100;++i)
if (count_primes(i) - count_primes(i-1))
printf("%d ",i);puts("pr");*/
fact[0]=1;
for (int i=1;i<N;++i)
fact[i]=1ll*fact[i-1]*i%mod;
ifact[N-1]=ksm(fact[N-1],mod-2);
for (int i=N-2;i>=0;--i)
ifact[i]=(i+1ll)*ifact[i+1]%mod;
scanf("%lld",&n);
long long res = 1;
for (long long l = 1, r, o,tmp; l<=n; l = r + 1) {
o = n/l;
r = n/o;
tmp = count_primes(o)- count_primes(o/2);
if (o<=2) {
continue;
} else if (o==3) res = res * ksm(3ll, r-l+1) % mod;
else {
//printf("[%lld - %lld] [n/d] = %lld, tmp = %lld\n", l, r, o, tmp);
res = res * ksm((o - tmp - 1ll)%mod * ksm(o % mod, tmp) % mod, r-l+1) % mod;
}
}
printf("%lld\n",res);
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 43ms
memory: 73412kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 42ms
memory: 73808kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 40ms
memory: 73676kb
input:
123
output:
671840470
result:
ok answer is '671840470'
Test #4:
score: 0
Accepted
time: 42ms
memory: 73384kb
input:
233
output:
353738465
result:
ok answer is '353738465'
Test #5:
score: 0
Accepted
time: 44ms
memory: 73804kb
input:
5981
output:
970246821
result:
ok answer is '970246821'
Test #6:
score: 0
Accepted
time: 43ms
memory: 73312kb
input:
86422
output:
897815688
result:
ok answer is '897815688'
Test #7:
score: 0
Accepted
time: 42ms
memory: 73804kb
input:
145444
output:
189843901
result:
ok answer is '189843901'
Test #8:
score: 0
Accepted
time: 42ms
memory: 73232kb
input:
901000
output:
819449452
result:
ok answer is '819449452'
Test #9:
score: 0
Accepted
time: 44ms
memory: 73040kb
input:
1000000
output:
113573943
result:
ok answer is '113573943'
Test #10:
score: 0
Accepted
time: 46ms
memory: 73816kb
input:
23333333
output:
949849384
result:
ok answer is '949849384'
Test #11:
score: 0
Accepted
time: 48ms
memory: 75564kb
input:
102850434
output:
604886751
result:
ok answer is '604886751'
Test #12:
score: 0
Accepted
time: 78ms
memory: 86732kb
input:
998244353
output:
0
result:
ok answer is '0'
Test #13:
score: 0
Accepted
time: 79ms
memory: 86564kb
input:
1000000007
output:
318420284
result:
ok answer is '318420284'
Test #14:
score: 0
Accepted
time: 96ms
memory: 97360kb
input:
2147483547
output:
688759898
result:
ok answer is '688759898'
Test #15:
score: 0
Accepted
time: 165ms
memory: 120272kb
input:
5120103302
output:
116870489
result:
ok answer is '116870489'
Test #16:
score: 0
Accepted
time: 403ms
memory: 210608kb
input:
19834593299
output:
523663743
result:
ok answer is '523663743'
Test #17:
score: 0
Accepted
time: 928ms
memory: 376844kb
input:
52500109238
output:
195086665
result:
ok answer is '195086665'
Test #18:
score: 0
Accepted
time: 1349ms
memory: 525380kb
input:
84848352911
output:
107959260
result:
ok answer is '107959260'
Test #19:
score: 0
Accepted
time: 1535ms
memory: 591284kb
input:
99824435322
output:
0
result:
ok answer is '0'
Test #20:
score: 0
Accepted
time: 1480ms
memory: 591984kb
input:
99999999354
output:
316301711
result:
ok answer is '316301711'
Test #21:
score: 0
Accepted
time: 1496ms
memory: 592076kb
input:
100000000000
output:
396843576
result:
ok answer is '396843576'
Extra Test:
score: 0
Extra Test Passed