fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int mod = 1e9 + 7;
  5.  
  6. int main() {
  7. long long x, n, a = 1, b = 0;
  8. cin >> x >> n;
  9. for(int i = 1; i <= n; i++) {
  10. a = a * x % mod;
  11. if(i % 2 == 1) b = (b + a) % mod;
  12. else b = (b - a + mod) % mod;
  13. }
  14. cout << b;
  15. return 0;
  16. }
  17.  
Success #stdin #stdout 0.01s 5320KB
stdin
2 4 
stdout
999999997