fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define M 1000000007
  5.  
  6. #define mp make_pair
  7. #define pb push_back
  8. #define tri pair<int, pair<int, int> >
  9. #define TRI(a,b,c) (make_pair(a,make_pair(b,c)))
  10.  
  11. typedef long long ll;
  12. typedef long double ld;
  13.  
  14. ll powmod(ll x, ll y)
  15. {
  16. if(y==0) return 1;
  17. ll ret = powmod(x, y/2);
  18. if(y%2==0) return (ret*ret)%M;
  19. else return (((ret*ret)%M)*x)%M;
  20. }
  21.  
  22. int main()
  23. {
  24. ios_base::sync_with_stdio(false);
  25. cin.tie(NULL);
  26. cout.tie(NULL);
  27. int t; cin>>t;
  28. for(int t0=0; t0<t; t0++)
  29. {
  30. ll m, k; cin>>m>>k;
  31. ll ans = 0, curr = 1;
  32. for(int i=0; i<k; i++)
  33. {
  34. ans = (ans+curr)%M;
  35. curr = (curr*m)%M;
  36. }
  37. if(k>1)ans = (ans+(k-2)/(m-1)+1)%M;
  38. cout<<ans<<endl;
  39. }
  40. return 0;
  41. }
Success #stdin #stdout 0s 4400KB
stdin
3
5 2
3 3
2 16
stdout
7
14
65550