QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#276700#6235. 随机数生成器SoyTony0 0ms3944kbC++141.3kb2023-12-06 09:42:292023-12-06 09:42:29

Judging History

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

  • [2023-12-06 09:42:29]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3944kb
  • [2023-12-06 09:42:29]
  • 提交

answer

/*
Xn+1=a*Xn+1*c

Xn  a*Xn+1*c
c   0*Xn+1*c

c:
a 1
0 1

f:
X0
c
*/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<stdio.h>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
typedef long long lint;
const int maxn=4;
//const int mod=1e9+7;
inline lint read(){
	lint x=0,w=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
	while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
	return x*w;
}
struct node{
	lint num[maxn][maxn];
}f,ch;
lint m,a,c,x0,n,mod;
inline lint q_mul(lint x,lint y){
	lint ans=0;
	while(y){
		if(y&1){
			ans=(ans+x)%m;
		}
		x=(x+x)%m;
		y>>=1;
	}
	return ans;
}
inline node work(node x,node y){
	node tmp;
	memset(tmp.num,0,sizeof(tmp.num));
	for(int i=1;i<=2;i++){
		for(int j=1;j<=2;j++){
			for(int k=1;k<=2;k++){
				tmp.num[i][j]=(tmp.num[i][j]+q_mul(x.num[i][k]%m,y.num[k][j]%m))%m;
			}
		}
	}
	return tmp;
}
void q_pow(lint x){
	f.num[1][1]=x0,f.num[1][2]=c;
	ch.num[1][1]=a,ch.num[1][2]=0,ch.num[2][1]=1,ch.num[2][2]=1;
	while(x){
		if(x&1){
			f=work(f,ch);
		}
		ch=work(ch,ch);
		x>>=1;
	}
}
int main(){
	m=read(),a=read(),c=read(),x0=read(),n=read(),mod=read();
	q_pow(n);
	printf("%lld",f.num[1][1]%mod);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3880kb

input:

31 23 17 15 3137
7 8 0

output:

3

result:

wrong answer 1st numbers differ - expected: '1', found: '3'

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 3808kb

input:

5732 32 44 550 123457
150 120 0

output:

24

result:

wrong answer 1st numbers differ - expected: '1', found: '24'

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 3884kb

input:

4231222 93 71901 927775 72345703
200 200 0

output:

94

result:

wrong answer 1st numbers differ - expected: '1', found: '94'

Test #4:

score: 0
Wrong Answer
time: 0ms
memory: 3828kb

input:

1234567 197 98749347 66033937 98765441
2000 2000 16000
18041 129030
24010 2881443
24033 3054034
161252 120065
144057 1113525
96468 32036
612329 116065
8076 106219
34050 3442472
184068 1519836
108071 520016
3379879 188095
66071 459239
3924895 104093
56047 529160
3703422 88019
469187 80078
2212425 600...

output:

684

result:

wrong answer 1st numbers differ - expected: '1', found: '684'

Test #5:

score: 0
Wrong Answer
time: 0ms
memory: 3944kb

input:

220033 163 32964973 50146828 88265447
2000 2000 10001
42028 3259156
2123521 56005
104006 3490685
102048 1592266
132053 1567833
130019 551217
6070 2400169
36031 2979949
80006 3678634
1086862 140063
16 554706
38008 3234502
108023 1325052
1157881 112010
18052 3023143
20050 3705118
3488182 20055
779681 ...

output:

1714

result:

wrong answer 1st numbers differ - expected: '1', found: '1714'

Test #6:

score: 0
Wrong Answer
time: 0ms
memory: 3728kb

input:

9020033 223 61543787 95782146 98965439
2000 2000 12100
30052 2360033
2798156 66043
52052 749374
1270053 62046
316649 8
8041 171190
118045 2288631
98032 1981195
2366478 74042
118008 261327
36008 2489080
113570 42046
132047 2536642
60053 1382662
74019 2113777
80042 2268302
1691588 126002
2664888 40010...

output:

1729

result:

wrong answer 1st numbers differ - expected: '1', found: '1729'

Test #7:

score: 0
Wrong Answer
time: 0ms
memory: 3796kb

input:

7020277 176 78786360 57478061 91965439
5000 5000 23000
10524592 455097
225093 8193127
16830186 145096
65008 19729755
500057 3346073
23493254 290032
18074161 275037
405041 6927135
15512740 375017
11617444 490025
15084 21484843
20768322 55010
445013 1208799
95048 12259487
14763755 450092
365062 811007...

output:

447

result:

wrong answer 1st numbers differ - expected: '1', found: '447'

Test #8:

score: 0
Wrong Answer
time: 0ms
memory: 3692kb

input:

2312255 278 62630371 53301066 99995923
5000 5000 40000
24980190 320058
635001 24980191
5648562 495018
725057 8040734
325043 24980194
24206524 460093
20971572 730098
240061 12893364
480010 9389109
45040 24980199
740003 24980200
625080 12849820
24266160 745089
24980203 40145
95037 1171740
12076524 140...

output:

1770

result:

wrong answer 1st numbers differ - expected: '1', found: '1770'

Test #9:

score: 0
Wrong Answer
time: 0ms
memory: 3736kb

input:

2312255 279 3507885 55065619 99995923
5000 5000 50000
12411599 510042
9458515 510068
17180332 385087
255076 4340703
24970890 805109
24970891 80031
13829626 80081
660016 5373385
24224203 285090
425009 12372994
22150601 850070
24970897 635147
24970898 670164
12921645 70130
535155 24970900
24970901 505...

output:

431

result:

wrong answer 1st numbers differ - expected: '1', found: '431'

Test #10:

score: 0
Wrong Answer
time: 0ms
memory: 3804kb

input:

7012255 104 14758497 38070665 97795417
5000 5000 35000
740057 1488844
16425638 365098
10033259 310143
17813477 450085
400089 3137378
150011 18362827
445130 14285066
24978098 410072
185064 20009840
24978100 400099
19174287 515036
23242725 75087
11975709 405008
24978104 720067
680144 24978105
24978106...

output:

1732

result:

wrong answer 1st numbers differ - expected: '1', found: '1732'