fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. #include <ext/pb_ds/trie_policy.hpp>
  5. using namespace std;
  6. using namespace __gnu_pbds;
  7. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
  8. typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;
  9. typedef unsigned long long BITMASK; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<long long, long long> pll;
  10. #define has_bit(bit_mask, x) ((bit_mask) & (1ULL << (x)))
  11. #define turn_on_bit(bit_mask, x) (bit_mask |= (1ULL << (x)))
  12. #define turn_off_bit(bit_mask, x) (bit_mask &= (~(1ULL << (x))))
  13. #define smallest_on_bit(bit_mask) (__builtin_ctzint((bit_mask) & (-(bit_mask))))
  14. #define CLOCK_START clock_t chrono_clk_beg = clock()
  15. #define CLOCK_END clock_t chrono_clk_end = clock(); cerr << (double(chrono_clk_end - chrono_clk_beg) / CLOCKS_PER_SEC) << " sec"
  16. #define bug(args ...) cerr << __LINE__ << ">> ", err(new istringstream(string(#args)), args), cerr << '\n'
  17. #define decToBin(name, num) string name = bitset<8>(num).to_string();
  18. #define binToDec(name, binary) unsigned long name = bitset<8>(binary).to_ulong();
  19. #define radToDeg(name, radians) double name = radians * 180 / M_PI;
  20. #define all(x) x.begin(), x.end()
  21. #define removeDuplicates(vec) sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end())
  22. #define printMat(mat) for (auto &x : mat) { for (auto &y : x) { if (y < INF) cout << setw(7) << y; else cout << setw(7) << "-"; } cout << '\n'; }
  23. #define fillMat(mat, n, m, x) for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) mat[i][j] = x;
  24. #define printArr(arr) for (auto &x : arr) cout << x << " "; cout << '\n';
  25. #define arrReplace(arr, from, to) for (auto &x : arr) if (x == from) x = to;
  26. #define INF (1LL<<30)
  27. #define INF32 (1LL<<62)
  28. #define F first
  29. #define S second
  30. #define M_PI 3.14159265358979323846
  31. #define MOD 10000007
  32. #define int ll
  33. inline int powMod(int a, int b) { int x = 1; while (b > 0) { if (b&1) x = (x*a) % MOD; a = (a*a) % MOD; b >>= 1; } return x; }
  34. inline int multiply(int x, int y) { return ((x % MOD) * (y % MOD)) % MOD; }
  35. inline int divide(int x, int y) { return ((x % MOD) * powMod(y % MOD, MOD-2)) % MOD; }
  36. inline int gcd (int a, int b) { while (b) { a %= b; swap(a, b); } return a; }
  37. inline int lcm (int a, int b) { return a / gcd(a, b) * b; }
  38. inline int ceil(int a, int b) { return (a+b-1)/b; }
  39. void err(istringstream *iss) {} template<typename T, typename ... Args> void err(istringstream *iss, const T &_val, const Args & ... args) { string _name; *iss >> _name; if (_name.back()==',') _name.pop_back(); cerr << _name << " = " << _val << "; ", err(iss, args ...); }
  40. int str_replace(string& str, const string& from, const string& to, int limit = -1) { if(from.empty()) return 0; size_t start_pos = 0; int cnt = 0; while((start_pos = str.find(from, start_pos)) != std::string::npos) { str.replace(start_pos, from.length(), to); start_pos += to.length(); cnt++; if (cnt == limit) break; } return cnt; }
  41.  
  42. signed main()
  43. {
  44. ios_base::sync_with_stdio(false); cin.tie(NULL);
  45. int n, k;
  46. while (cin >> n >> k)
  47. {
  48. if (n == 0 || k == 0) break;
  49. int ans = multiply(2, powMod(n-1, n-1));
  50. ans = (ans + powMod(n, n)) % MOD;
  51. ans = (ans + multiply(2, powMod(n-1, k))) % MOD;
  52. ans = (ans + powMod(n, k)) % MOD;
  53. cout << ans << '\n';
  54. }
  55. return 0;
  56. }
Success #stdin #stdout 0s 4252KB
stdin
Standard input is empty
stdout
Standard output is empty