QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#128985#273. 类欧几里得算法AFewSuns#100 ✓137ms3876kbC++142.5kb2023-07-21 17:41:502023-07-21 17:41:51

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-21 17:41:51]
  • 评测
  • 测评结果:100
  • 用时:137ms
  • 内存:3876kb
  • [2023-07-21 17:41:50]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll long long
	#define bl bool
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 1e18
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
#define mod 1000000007
ll t,n,a,b,c,k1,k2,C[11][11];
struct node{
	ll cnt1,cnt2,ans[11][11];
}I;
il node operator*(const node &x,const node &y){
	node res=I;
	res.cnt1=(x.cnt1+y.cnt1)%mod;
	res.cnt2=(x.cnt2+y.cnt2)%mod;
	fr(i,0,k1){
		fr(j,0,k2){
			res.ans[i][j]=x.ans[i][j];
			ll pw1=1;
			fr(ii,0,i){
				ll pw2=1;
				fr(jj,0,j){
					res.ans[i][j]=(res.ans[i][j]+C[i][ii]*C[j][jj]%mod*pw1%mod*pw2%mod*y.ans[i-ii][j-jj]%mod)%mod;
					pw2=pw2*x.cnt2%mod;
				}
				pw1=pw1*x.cnt1%mod;
			}
		}
	}
	return res;
}
node mpow(node x,ll y){
	node res=I;
	while(y){
		if(y&1) res=res*x;
		x=x*x;
		y>>=1;
	}
	return res;
}
node solve(ll P,ll Q,ll R,ll N,node A,node B){
	if(!N) return I;
	if(P>=Q) return solve(P%Q,Q,R,N,A,mpow(A,P/Q)*B);
	ll m=(P*N+R)/Q;
	if(!m) return mpow(B,N);
	else return mpow(B,(Q-R-1)/P)*A*solve(Q,P,(Q-R-1)%P,m-1,B,A)*mpow(B,N-(Q*m-R-1)/P);
}
int main(){
	t=read();
	node U=I,R=I;
	R.cnt1=1;
	fr(i,0,10) R.ans[i][0]=1;
	U.cnt2=1;
	fr(i,0,10){
		C[i][0]=1;
		fr(j,1,i) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
	}
	while(t--){
		n=read();
		a=read();
		b=read();
		c=read();
		k1=read();
		k2=read();
		node res=mpow(U,b/c)*solve(a,c,b%c,n,U,R);
		writeln((my_pow(0,k1,mod)*my_pow(b/c,k2,mod)%mod+res.ans[k1][k2])%mod);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 17ms
memory: 3592kb

input:

1000
846930887 681692778 714636916 89384 0 1
424238336 719885387 649760493 47794 0 1
189641422 25202363 350490028 16650 0 1
102520060 44897764 967513927 68691 0 1
540383427 304089173 303455737 80541 0 1
521595369 294702568 726956430 5212 0 1
861021531 278722863 233665124 65783 0 1
468703136 10151393...

output:

787440837
603410377
723035859
327613252
213481743
197744321
183595532
306097937
945612263
462240557
878873337
913033603
276973800
137776104
471637127
36869524
59950373
599468074
662996688
39221965
159523453
603757410
863747292
125209174
321695224
581226543
502962761
546511215
492741651
881346590
834...

result:

ok 1000 numbers

Test #2:

score: 10
Accepted
time: 18ms
memory: 3836kb

input:

1000
846930887 681692778 714636916 89384 0 1
424238336 719885387 649760493 47794 0 1
189641422 25202363 350490028 16650 0 1
102520060 44897764 967513927 68691 0 1
540383427 304089173 303455737 80541 0 1
521595369 294702568 726956430 5212 0 1
861021531 278722863 233665124 65783 0 1
468703136 10151393...

output:

787440837
603410377
723035859
327613252
213481743
197744321
183595532
306097937
945612263
462240557
878873337
913033603
276973800
137776104
471637127
36869524
59950373
599468074
662996688
39221965
159523453
603757410
863747292
125209174
321695224
581226543
502962761
546511215
492741651
881346590
834...

result:

ok 1000 numbers

Test #3:

score: 10
Accepted
time: 13ms
memory: 3876kb

input:

1000
846930887 681692778 714636916 89384 1 0
649760493 596516650 189641422 85387 0 1
102520060 44897764 967513927 68691 0 0
303455737 35005212 521595369 89173 1 0
861021531 278722863 233665124 65783 1 0
801979803 315634023 635723059 13930 1 0
89018457 628175012 656478043 61394 1 0
914544920 60841378...

output:

590247101
607294734
102520061
988535616
258549494
359848706
860104659
914544921
806512744
219134560
36869524
54386320
1100547
760313752
603757410
510232691
82579690
843146721
36876088
935671592
290199337
365292116
534011850
126900199
669344073
690573152
719144156
644864030
602224207
100895714
452066...

result:

ok 1000 numbers

Test #4:

score: 10
Accepted
time: 16ms
memory: 3700kb

input:

1000
846930887 681692778 714636916 89384 1 0
649760493 596516650 189641422 85387 0 1
102520060 44897764 967513927 68691 0 0
303455737 35005212 521595369 89173 1 0
861021531 278722863 233665124 65783 1 0
801979803 315634023 635723059 13930 1 0
89018457 628175012 656478043 61394 1 0
914544920 60841378...

output:

590247101
607294734
102520061
988535616
258549494
359848706
860104659
914544921
806512744
219134560
36869524
54386320
1100547
760313752
603757410
510232691
82579690
843146721
36876088
935671592
290199337
365292116
534011850
126900199
669344073
690573152
719144156
644864030
602224207
100895714
452066...

result:

ok 1000 numbers

Test #5:

score: 10
Accepted
time: 132ms
memory: 3660kb

input:

1000
846930887 681692778 714636916 89384 3 3
649760493 596516650 189641422 85387 2 3
102520060 44897764 967513927 68691 0 6
303455737 35005212 521595369 89173 7 0
861021531 278722863 233665124 65783 7 1
801979803 315634023 635723059 13930 9 0
89018457 628175012 656478043 61394 9 0
914544920 60841378...

output:

269986411
687117872
337796106
649269006
273534477
925890819
789776059
781917067
471414212
683680813
655243026
766680733
110386800
920667633
42177293
33248798
268698025
97602241
455950431
787378605
628127823
884695308
910301084
481441390
301149571
40678494
744524425
997602040
853435603
942399367
4371...

result:

ok 1000 numbers

Test #6:

score: 10
Accepted
time: 132ms
memory: 3664kb

input:

1000
846930887 681692778 714636916 89384 3 3
649760493 596516650 189641422 85387 2 3
102520060 44897764 967513927 68691 0 6
303455737 35005212 521595369 89173 7 0
861021531 278722863 233665124 65783 7 1
801979803 315634023 635723059 13930 9 0
89018457 628175012 656478043 61394 9 0
914544920 60841378...

output:

269986411
687117872
337796106
649269006
273534477
925890819
789776059
781917067
471414212
683680813
655243026
766680733
110386800
920667633
42177293
33248798
268698025
97602241
455950431
787378605
628127823
884695308
910301084
481441390
301149571
40678494
744524425
997602040
853435603
942399367
4371...

result:

ok 1000 numbers

Test #7:

score: 10
Accepted
time: 137ms
memory: 3664kb

input:

1000
846930887 681692778 714636916 89384 3 3
649760493 596516650 189641422 85387 2 3
102520060 44897764 967513927 68691 0 6
303455737 35005212 521595369 89173 7 0
861021531 278722863 233665124 65783 7 1
801979803 315634023 635723059 13930 9 0
89018457 628175012 656478043 61394 9 0
914544920 60841378...

output:

269986411
687117872
337796106
649269006
273534477
925890819
789776059
781917067
471414212
683680813
655243026
766680733
110386800
920667633
42177293
33248798
268698025
97602241
455950431
787378605
628127823
884695308
910301084
481441390
301149571
40678494
744524425
997602040
853435603
942399367
4371...

result:

ok 1000 numbers

Test #8:

score: 10
Accepted
time: 136ms
memory: 3640kb

input:

1000
846930887 681692778 714636916 89384 3 3
649760493 596516650 189641422 85387 2 3
102520060 44897764 967513927 68691 0 6
303455737 35005212 521595369 89173 7 0
861021531 278722863 233665124 65783 7 1
801979803 315634023 635723059 13930 9 0
89018457 628175012 656478043 61394 9 0
914544920 60841378...

output:

269986411
687117872
337796106
649269006
273534477
925890819
789776059
781917067
471414212
683680813
655243026
766680733
110386800
920667633
42177293
33248798
268698025
97602241
455950431
787378605
628127823
884695308
910301084
481441390
301149571
40678494
744524425
997602040
853435603
942399367
4371...

result:

ok 1000 numbers

Test #9:

score: 10
Accepted
time: 136ms
memory: 3704kb

input:

1000
846930887 681692778 714636916 89384 3 3
649760493 596516650 189641422 85387 2 3
102520060 44897764 967513927 68691 0 6
303455737 35005212 521595369 89173 7 0
861021531 278722863 233665124 65783 7 1
801979803 315634023 635723059 13930 9 0
89018457 628175012 656478043 61394 9 0
914544920 60841378...

output:

269986411
687117872
337796106
649269006
273534477
925890819
789776059
781917067
471414212
683680813
655243026
766680733
110386800
920667633
42177293
33248798
268698025
97602241
455950431
787378605
628127823
884695308
910301084
481441390
301149571
40678494
744524425
997602040
853435603
942399367
4371...

result:

ok 1000 numbers

Test #10:

score: 10
Accepted
time: 136ms
memory: 3768kb

input:

1000
846930887 681692778 714636916 89384 3 3
649760493 596516650 189641422 85387 2 3
102520060 44897764 967513927 68691 0 6
303455737 35005212 521595369 89173 7 0
861021531 278722863 233665124 65783 7 1
801979803 315634023 635723059 13930 9 0
89018457 628175012 656478043 61394 9 0
914544920 60841378...

output:

269986411
687117872
337796106
649269006
273534477
925890819
789776059
781917067
471414212
683680813
655243026
766680733
110386800
920667633
42177293
33248798
268698025
97602241
455950431
787378605
628127823
884695308
910301084
481441390
301149571
40678494
744524425
997602040
853435603
942399367
4371...

result:

ok 1000 numbers