QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#61342#4499. Find differentAppleblue17AC ✓410ms6704kbC++14984b2022-11-12 14:17:102022-11-12 14:17:13

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-12 14:17:13]
  • Judged
  • Verdict: AC
  • Time: 410ms
  • Memory: 6704kb
  • [2022-11-12 14:17:10]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
const long long N=1e5+5,mod=998244353;
long long ksm(long long a,long long x){
	long long tot=1;
	while(x){
		if(x & 1ll) tot=tot*a%mod;
		a=a*a%mod;
		x>>=1;
	}
	return tot;
}

bool pd[N];
long long pr[N],phi[N];
long long cnt;

void init(long long lim){
	pd[1]=1,phi[1]=1;
	for(long long i=2;i<=lim;i++){
		if(!pd[i]) pr[++cnt]=i,phi[i]=i-1;
		for(long long j=1;j<=cnt && i*pr[j]<=lim;j++){
			pd[i*pr[j]]=1;
			if(i%pr[j]) phi[i*pr[j]]=phi[i]*(pr[j]-1);
			else{
				phi[i*pr[j]]=phi[i]*pr[j];
				break;
			}
		}
	}
}

long long T,n,m,f[N],g[N],h[N];

int main(){
	init(N-5);
	cin>>T;
	while(T--){
		scanf("%lld%lld",&n,&m);
		for(long long i=1;i<=n;i++) f[i]=phi[i]*__gcd(m,i)%mod,g[i]=ksm(m,i-1),h[i]=0;
		for(long long i=1;i<=n;i++){
			for(long long j=i;j<=n;j+=i) h[j]=(h[j]+f[i]*g[j/i]%mod)%mod;
		}
		for(long long i=1;i<=n;i++) cout<<h[i]*ksm(i,mod-2)%mod<<" ";
		cout<<'\n';
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 410ms
memory: 6704kb

input:

100
100000 100000
100000 10007
100000 99991
99999 65536
100000 39366
100000 1
100000 2
100000 3
100000 4
91 14575
92 79445
92 90081
92 90629
96 47202
95 94325
93 4784
97 2156
92 35902
94 78537
91 30739
90 29211
100 38506
98 86568
100 60016
90 96263
100 1449
95 90310
94 77068
99 8580
95 49218
96 9432...

output:

1 50001 338600275 682529035 345997022 799071125 767573961 525777344 672451750 695859947 80705839 973419437 270876600 831711420 936750132 722158139 215082649 400813551 495979547 702209089 368345940 35630556 251536020 273337876 775086485 990484575 711464282 66329938 116620838 856606896 74334807 781842...

result:

ok 100 lines