2017乌鲁木齐ICPC: K. Sum of the Line(容斥)

 

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=ci​Tr,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,求

\small \sum_{i=1}^ni^2(gcd(n,i)=1)

 

思路:

可以说是非常水的容斥了,感觉只要把题意理解,知道是求上面那个式子就一定能过

对于n的所有质数,暴力枚举其倍数对答案的贡献即可,因为质数最多不超过9个,所以可以直接\small 2^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;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值