-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC.cpp
66 lines (66 loc) · 1.47 KB
/
C.cpp
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
#include <iostream>
#include <numeric>
#include <vector>
#include <functional>
#include <algorithm>
#include <set>
#include <queue>
#include <unordered_set>
#include <string>
#include <cstring>
#include <bitset>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> edge;
#define endl '\n'
#define pi acos(-1)
#define loop(i, k, n) for(int i = k; i<n; i++)
#define loopr(i, k, n) for(ll i = k; i >= n; i--)
#define clr(v, d) memset(v, d, sizeof(v))
#define sz(s) (ll)s.size()
#define all(v) (v).begin(), (v).end()
#define sum(n) (n*(n+1)/2)
#define F first
#define S second
#define test int test; cin >> test; while(test--)
void fast(){
cin.tie(nullptr);
istream::sync_with_stdio(false);
}
const ll N = 25, M = 1e3 + 5, mod = 1e9 + 7, OO = 0x3f3f3f3f;
// moves in grid
//int dx[] = {0, 0, 1, -1, 1, -1, -1, 1};
//int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
// knight moves
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2};
//int dy[] = {-1, -2, -2, -1, 1, 2, 2, 1};
ll fixMod(ll a, ll b){
return (a % b + b) % b;
}
ll a[M];
void solve() {
clr(a, 0);
ll p, n;
cin >> n >> p;
ll res = n;
a[1] = n;
loop(i, 2, p+1){
a[i] = (a[i - 1] * n);
res += a[i];
res = fixMod(res, mod);
}
cout << res;
}
int main() {
fast();
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
test{
solve();
}
return 0;
}