50158. Stop the Sequence
難度:2.5/51
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46#include <stdio.h>
#include <stdlib.h>
int a, b, c, d, e;
int cmp(const void* a, const void* b){
return *(int*)a - *(int*)b;
}
int get_c(int x){
int cnt = 0;
while(x < d || x > e){
x = (a * x + b) % c;
cnt++;
}
return cnt;
}
int is_conseq(int a[3]){
int b[3];
b[0] = a[0], b[1] = a[1], b[2] = a[2];
qsort(b, 3, sizeof(int), cmp);
if(b[1] == b[0] + 1 && b[2] == b[1] + 1) return 1;
else return 0;
}
int main(){
scanf("%d %d %d %d %d", &a, &b, &c, &d, &e);
int record[3] = {-100, -100, -100}, c_num[3] = {-100, -100, -100};
int found = 0;
int x;
while(scanf("%d", &x) != EOF){
record[0] = record[1], record[1] = record[2];
c_num[0] = c_num[1], c_num[1] = c_num[2];
record[2] = x, c_num[2] = get_c(x);
// printf("%d %d\n", x, get_c(x));
if(is_conseq(c_num)){
found = 1;
printf("%d %d %d\n", record[0], record[1], record[2]);
break;
}
}
if(!found) printf("Not found\n");
}