Advertisement
DaniDori

Untitled

Oct 17th, 2020
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. #include<string>
  4. using namespace std;
  5. int binpow(int a, int n) {
  6. if (n == 0)
  7. return 1;
  8. if (n % 2 == 1)
  9. return (binpow(a, n - 1) % 1000000007 * a) % 1000000007;
  10. else {
  11. int b = binpow(a, n / 2) % 1000000007;
  12. return ((b * b)%1000000007);
  13. }
  14. }
  15. int x(int a, int b) {
  16. int sum = 0;
  17. for (int i = 0; i < a; i++) {
  18. sum += b;
  19. sum %= 1000000007;
  20. }
  21. return sum;
  22. }
  23. int f(int a) {
  24. int ans = 1,count=1;
  25.  
  26. for (int i = a; i > 0; i--) {
  27. ans = x(ans, binpow(count, i));
  28. count++;
  29. }
  30. return ans;
  31. }
  32. int main() {
  33. int n,x;
  34. cin >> n;
  35. for (int i = 0; i < n; i++) {
  36. cin >> x;
  37. cout <<endl<< f(x) << "\n";
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement