fork download
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. #define int long long
  5. #define F first
  6. #define S second
  7. #define sz(x) ((int)x.size())
  8. #define rep(i,a,n) for (int i = a; i <= n; ++i)
  9. #define all(v) v.begin(), v.end()
  10. #define pb push_back
  11. #define P pair < int, int >
  12. #define E cout << '\n'
  13.  
  14. const int mod = 1e9 + 7;
  15. const int N = 3e5 + 5;
  16.  
  17. int gcd(int a, int b, int *x, int *y) {
  18. if (a == 0) {
  19. *x = 0;
  20. *y = 1;
  21. return b;
  22. }
  23. int x1, y1;
  24. int gcd1 = gcd(b%a, a, &x1, &y1);
  25. *x = y1 - (b/a) * x1;
  26. *y = x1;
  27. return gcd1;
  28. }
  29. int po(int x, int n, int mod) {
  30. int res = 1;
  31. while(n) {
  32. if (n & 1) {
  33. res = (res * x) % mod;
  34. }
  35. n /= 2;
  36. x = (x * x) % mod;
  37. }
  38. return res;
  39. }
  40. int get(int n, int mod) {
  41. int ans = 0;
  42. rep(i, 1, n)
  43. ans = (ans + po(i, i, mod)) % mod;
  44. return ans;
  45. }
  46. signed main() {
  47. int x, y, n, Mod = pow(5, 10);
  48. cin >> n;
  49.  
  50. int a = get(n, 1024);
  51.  
  52.  
  53. gcd(Mod, 1024, &x, &y);
  54.  
  55. int ans1 = x * Mod * a;
  56.  
  57. int b = get(n, Mod);
  58. // cout << a << ' ' << b << '\n';
  59. int ans2 = y * 1024 * b;
  60.  
  61. cout << ((ans1 + ans2 ) % (int)1e10 + (int)1e10) % (int)1e10;
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. return 0;
  73. }
Success #stdin #stdout 0s 15232KB
stdin
10
stdout
405071317