-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasdf.c
97 lines (77 loc) · 2.42 KB
/
asdf.c
1
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define T(x) ((x << 1) + (x << 3) + (str[k] - 48))
#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)
int MOD;
int n = 0, q = 0, ye = 0, ar[101000][25];
char str[10000100], str2[3000000], str3[15];
int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
long long int bigmod(long long int x, int n){
long long int res = 1;
while (n){
if (n & 1){
res = res * x;
if (res > MOD) res = (res % MOD);
}
x = (x * x);
if (x > MOD) x = (x % MOD);
n >>= 1;
}
return res;
}
int main(){
int query, i, j, k = 0, x, a, b;
fread_unlocked(str, 1, 10000000, stdin);
for (i = 0; i < 25; i++) ar[0][i] = 0;
while (str[k] < 48 || str[k] > 57) k++;
for (; str[k] > 47 && str[k] < 58; k++) n = T(n);
for (i = 1; i <= n; i++){
x = 0;
while (str[k] < 48 || str[k] > 57) k++;
for (; str[k] > 47 && str[k] < 58; k++) x = T(x);
for (j = 0; j < 25; j++){
ar[i][j] = ar[i - 1][j];
int p = primes[j];
while ((x % p) == 0){
ar[i][j]++;
x /= p;
}
}
}
while (str[k] < 48 || str[k] > 57) k++;
for (; str[k] > 47 && str[k] < 58; k++) q = T(q);
for (query = 0; query < q; query++){
a = 0, b = 0, MOD = 0;
while (str[k] < 48 || str[k] > 57) k++;
for (; str[k] > 47 && str[k] < 58; k++) a = T(a);
while (str[k] < 48 || str[k] > 57) k++;
for (; str[k] > 47 && str[k] < 58; k++) b = T(b);
while (str[k] < 48 || str[k] > 57) k++;
for (; str[k] > 47 && str[k] < 58; k++) MOD = T(MOD);
long long int res = 1;
if (MOD > 1){
for (j = 0; j < 25; j++){
x = ar[b][j] - ar[a - 1][j];
if (x){
int y = bigmod(primes[j], x);
res = (res * y) % MOD;
}
}
}
else res = 0;
j = 0;
x = res;
for (; ;){
if (!x) break;
str3[j++] = (x % 10) + 48;
x *= 0.1;
}
if (!j) str3[j++] = 48;
for (i = j - 1; i >= 0; i--) str2[ye++] = str3[i];
str2[ye++] = 10;
}
fwrite_unlocked(str2, 1, ye, stdout);
return 0;
}