#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<unordered_map> usingnamespacestd; constint N = 5e6 + 10; constint mod = 1e9 + 7; typedeflonglong ll;
bool notprime[N]; int prime[N], cnt; int sumf[N]; int f[N]; unordered_map<int, int> v; intaddmod(ll x, ll y) { if (y < 0) y += mod; if (x + y >= mod) x -= mod; return x + y; } intqpow(int a, int x, int mo) { int res = 1; while (x) { if (x & 1) res = 1ll * res * a % mo; a = 1ll * a * a % mo; x >>= 1; } return res; } voidmublus() { f[1] = 1; for (int i = 2; i < N; i++) { if (!notprime[i]) { f[i] = (1ll * i * i - 1) % mod; prime[++cnt] = i; } for (int j = 1; j <= cnt && prime[j] * i < N; j++) { notprime[prime[j] * i] = true; if (i % prime[j]) { f[i * prime[j]] = 1ll * f[i] * (1ll * prime[j] * prime[j] % mod - 1) % mod; } else { f[i * prime[j]] = 1ll * f[i] * prime[j] % mod * prime[j] % mod; break; } } } for (int i = 1; i < N; i++) sumf[i] = addmod(sumf[i - 1], f[i]); } int k, kk, inv6; intgetsum(int x) { if (x == 1) return kk - 1; return1ll * x * addmod(qpow(x, k, mod), -x) % mod * qpow(x - 1, mod - 2, mod) % mod; } intgetsumx2(int x) { return1ll * x * (x + 1) % mod * (2 * x + 1) % mod * inv6 % mod; } intgetf(int x) { if (x < N) return sumf[x]; if (v[x]) return v[x]; int ans = getsumx2(x); for (int i = 2, j; i <= x; i = j + 1) { j = x / (x / i); ans = addmod(ans, -(1ll * (j - i + 1) * getf(x / i) % mod)); } return v[x] = ans; }
int n, T; char str[N]; intmain() { mublus(); inv6 = qpow(6, mod - 2, mod); scanf("%d", &T); while (T--) { scanf("%d", &n); scanf("%s", str);
int ans = 0; int len = strlen(str); int p = mod - 1; k = 0; kk = 0; for (int i = 0; i < len; i++) { k = addmod(1ll * k * 10 % p, str[i] - '0'); kk = addmod(1ll * kk * 10 % mod, str[i] - '0'); } //cout << getf(3) << endl; for (int i = 1, j; i <= n; i = j + 1) { j = n / (n / i); //cout << n / i << " " << getsum(n / i) << endl; ans = addmod(ans, 1ll * addmod(getf(j), -getf(i - 1)) * getsum(n / i) % mod); } cout << ans << endl; } }