fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3.  
  4. using namespace std;
  5.  
  6. const int MOD = 1e9 + 7;
  7.  
  8. void solve(){
  9. ll n, k;
  10. cin >> n >> k;
  11.  
  12. if(k == 1){
  13. cout << (n % MOD)<< "\n";
  14. return;
  15. }
  16. ll p = k - 1, q = k - 1;
  17.  
  18. ll cnt = 2;
  19. while(q != 0){
  20. ll next = (p + q);
  21. next %= k;
  22. p = q;
  23. q = next;
  24. cnt++;
  25. cnt %= MOD;
  26. }
  27. n %= MOD;
  28. cnt %= MOD;
  29. n *= cnt;
  30. n %= MOD;
  31. cout << n << "\n";
  32.  
  33. }
  34.  
  35. int main(){
  36. ios_base::sync_with_stdio(false);
  37. cin.tie(nullptr);
  38.  
  39. int t = 1;
  40. cin >> t;
  41.  
  42. for(int i = 1; i <= t; i++){
  43. solve();
  44. }
  45. return 0;
  46. }
Success #stdin #stdout 0s 5284KB
stdin
3
3 2
100 1
1000000000000 1377
stdout
9
100
999244007