如果p是一个质数,而整数a不是p的倍数,则有a(p-1)≡1(mod p)。
题解:
这题考点是数列的极限以及费⻢⼩定理,⾸先我们对极限进⾏求解,得到 ,因为要取模,⽽除法不能直接
取模,所以我们需要使⽤逆元的概念,于是费⻢⼩定理 :然后快速幂解决即可。
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
const int mod = 1e9 + 7;
typedef long long ll;
ll powmod(ll a, ll b)
{
a %= mod;
ll res = 1;
while(b) {
if(b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int main()
{
int T;
ll a, c;
cin >> T;
while(T--) {
cin >> a >> c;
cout << ((powmod(c, 2) * powmod(2, (mod - 2))) % mod + (a % mod) * (c % mod) % mod) % mod<< endl;
}
}