-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathicpc_preli_i.cpp
More file actions
60 lines (48 loc) · 804 Bytes
/
icpc_preli_i.cpp
File metadata and controls
60 lines (48 loc) · 804 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int counter = 0,n;
int a[100000];
int dp[100000];
int bigmod(int a , int b, int M)
{
if(b == 0)
return 1 % M;
int x = bigmod(a, b / 2, M);
x = (x*x) % M;
if(b % 2 == 1)
x = (x * a) % M;
return x;
}
void g(int k)
{
if(k == n)
{
counter++;
return ;
}
for(int i = 0; i < 2 ; i++)
{
if(a[k - 1] == 1 && i == 1)
return ;
//counter++;
a[k] = i;
g(k + 1);
}
}
int main()
{
int t, k , M;
cin >> t;
for(int i = 0 ; i < t ; i++)
{
counter = 0;
cin >> n >> k >> M;
a[0] = 0;
g(0);
cout << "Case " << i+1 << ": " << bigmod(k, counter, M) << endl;
//cout << counter << endl;
}
//n = 3;
//cout << counter << endl;
return 0;
}