1005 huntian oy

g c d ( i a − j a , i b − j b ) = ( i − j ) ∗ g c d ( i , j ) gcd(i^a-j^a,i^b-j^b) = (i-j)*gcd(i,j) gcd(iaja,ibjb)=(ij)gcd(i,j)
a n s ( n ) = 1 / 2 ∗ i ∗ ϕ ( i ) ans(n) = 1/2*i*\phi(i) ans(n)=1/2iϕ(i)
特判 i=1时为0,最后要减去



#include 
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a, LL b) {LL s = 1; while (b > 0) {if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1;} return s;}
LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
typedef pair<int, int> P;


const int maxn = 1e6 + 10;

int Prime[maxn], f[maxn];
int Sum[maxn];
bool vis[maxn];
int cnt = 0;
void Init() {
	int N = maxn - 1;
	f[1] = 1;
	Sum[1] = 1;
	for (int i = 2; i <= N; ++i) {
		if (!vis[i]) {
			Prime[cnt++] = i;
			f[i] = i - 1 ;
		}
		for (int j = 0; j < cnt; ++j) {
			if (1ll * Prime[j]*i > N) break;
			vis[i * Prime[j]] = 1;
			if (i % Prime[j])
				f[i * Prime[j]] = 1ll * f[i] * f[Prime[j]] % mod;
			else {
				f[i * Prime[j]] = 1ll * f[i] * Prime[j] % mod;
				break;
			}
		}
		Sum[i] = (Sum[i - 1] + 1ll * f[i] * i % mod) % mod;
	}
}
map<int, int> ma;
LL inv6 = qpow(6, mod - 2);
LL Go(int n) {
	if (n < maxn) return Sum[n] % mod;
	if (ma[n] != 0) return ma[n];
	LL ans = 1ll * (n + 1) * n % mod * (2 * n + 1) % mod * inv6 % mod;
	for (int i = 2; i <= n; ) {
		int j = n / (n / i);
		ans  = (ans + mod - 1ll * (1ll * (j + 1) * j / 2 - 1ll * i * (i - 1) / 2) % mod * Go(n / i) % mod) % mod;
		i = j + 1;
	}
	return ma[n] = ans;
}
int main(void)
{
	Init();
	// cout << Sum[100] << endl;

	int T; cin >> T;

	int inv2 = qpow(2, mod - 2);
	while (T--) {
		int n, a, b;
		scanf("%d%d%d", &n, &a, &b);

		printf("%lld\n", (Go(n) - 1 + mod) % mod * inv2 % mod);
	}

	return 0;
}

你可能感兴趣的:(1005 huntian oy)