Advertisement
YEZAELP

B. Special Numbers

Nov 2nd, 2021
924
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using lli = long long;
  5. const lli mod = 1e9 + 7;
  6.  
  7. lli Solve(lli n, lli k){
  8.     lli p = 1, s = 0;
  9.     while(k > 0){
  10.         if(k & 1 == 1)
  11.             s = (s + p) % mod;
  12.         k = k >> 1;
  13.         p = (p * n) % mod;
  14.     }
  15.     return s;
  16. }
  17.  
  18. int main(){
  19.  
  20.     int Q;
  21.     scanf("%d", &Q);
  22.  
  23.     while(Q--){
  24.         lli n, k;
  25.         scanf("%lld%lld", &n, &k);
  26.         printf("%lld\n", Solve(n, k));
  27.     }
  28.  
  29.     return 0;
  30. }
Advertisement
RAW Paste Data Copied
Advertisement