-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsequa.cpp
More file actions
45 lines (38 loc) · 722 Bytes
/
sequa.cpp
File metadata and controls
45 lines (38 loc) · 722 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
#include <bits/stdc++.h>
using namespace std;
unsigned long long int calc(unsigned long long int n,unsigned long long int p,unsigned long long int m)
{
if(p==0)
return 1;
unsigned long long int nm = n%m;
unsigned long long int r = calc(nm,p/2,m);
r = (r*r)%m;
if(p%2==0)
return r;
return (r*nm)%m;
}
unsigned long long int loopi(unsigned long long int n,unsigned long long int m)
{
unsigned long long int sum=0;
if(n > 0)
{
sum=sum+1;
for (unsigned long long int i = 1 ;i <=n; ++i)
{
sum = (sum+calc(i,i,m))%m;
}
return sum;
}
}
int main()
{
int test;
unsigned long long int n,m,res;
cin >> test;
while(test--)
{
cin >> n >> m;
res = loopi(n,m);
cout << res << endl;
}
}