K. Sum of the Line
Consider a triangle of integers, denoted by TT. The value at (r,c)(r,c) is denoted by T_{r,c}Tr,c, where 1 \le r1≤r and 1 \le c \le r1≤c≤r. If the greatest common divisor of rr and cc is exactly 11, T_r,c = cTr,c=c, or 0 otherwise.
Now, we have another triangle of integers, denoted by SS. The value at (r,c)(r,c) is denoted by S_rSr,cc, where 1 \le r1≤r and 1 \le c \le r1≤c≤r. S_{r,c}Sr,c is defined as the summation \sum_{i=c}^{i} T_{r,i}∑i=ciTr,i.
Here comes your turn. For given positive integer k, you need to calculate the summation of elements in k-thk−th row of the triangle SS.
Input
The first line of input contains an integer t (1 \le t \le 10000)t(1≤t≤10000) which is the number of test cases. Each test case includes a single line with an integer kk described as above satisfying 2 \le k \le 10^82≤k≤108.
Output
For each case, calculate the summation of elements in the kk-th row of SS, and output the remainder when it divided by 998244353.
样例输入
2 2 3
样例输出
1 5
题意:
给你一个数字n,求
思路:
可以说是非常水的容斥了,感觉只要把题意理解,知道是求上面那个式子就一定能过
对于n的所有质数,暴力枚举其倍数对答案的贡献即可,因为质数最多不超过9个,所以可以直接暴力
#include<stdio.h>
#define LL long long
#define mod 998244353
#define nv 166374059
LL A(LL x) { return x*(x+1)%mod*(2*x+1)%mod*nv%mod; }
int pri[125];
int main(void)
{
LL ans, now;
int T, n, i, j, m, cnt, sum;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
m = n, cnt = 0;
for(i=2;i*i<=m;i++)
{
if(m%i==0)
pri[++cnt] = i;
while(m%i==0)
m /= i;
}
if(m!=1)
pri[++cnt] = m;
ans = A(n);
for(i=1;i<(1<<cnt);i++)
{
now = 1, sum = 0;
for(j=0;j<=cnt-1;j++)
{
if(i&(1<<j))
{
now *= pri[j+1];
sum++;
}
}
if(now<=n)
ans = (ans-now*now%mod*A(n/now)*(sum%2?1:-1)%mod+mod)%mod;
}
printf("%lld\n", ans);
}
return 0;
}