Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<string>
- using namespace std;
- int binpow(int a, int n) {
- if (n == 0)
- return 1;
- if (n % 2 == 1)
- return (binpow(a, n - 1) % 1000000007 * a) % 1000000007;
- else {
- int b = binpow(a, n / 2) % 1000000007;
- return ((b * b)%1000000007);
- }
- }
- int x(int a, int b) {
- int sum = 0;
- for (int i = 0; i < a; i++) {
- sum += b;
- sum %= 1000000007;
- }
- return sum;
- }
- int f(int a) {
- int ans = 1,count=1;
- for (int i = a; i > 0; i--) {
- ans = x(ans, binpow(count, i));
- count++;
- }
- return ans;
- }
- int main() {
- int n,x;
- cin >> n;
- for (int i = 0; i < n; i++) {
- cin >> x;
- cout <<endl<< f(x) << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement