题目描述

Consider a triangle of integers, denoted by T. The value at (r, c) is denoted by Tr,c , where 1 ≤ r and 1 ≤ c ≤ r. If the greatest common divisor of r and c is exactly 1, Tr,c = c, or 0 otherwise.
Now, we have another triangle of integers, denoted by S. The value at (r, c) is denoted by S r,c , where 1 ≤ r and 1 ≤ c ≤ r. S r,c is defined as the summation    
Here comes your turn. For given positive integer k, you need to calculate the summation of elements in k-th row of the triangle S.

输入

The first line of input contains an integer t (1 ≤ t ≤ 10000) which is the number of test cases.
Each test case includes a single line with an integer k described as above satisfying 2 ≤ k ≤ 10^8 .

输出

For each case, calculate the summation of elements in the k-th row of S, and output the remainder when it divided
by 998244353.

样例输入

2
2
3

样例输出

1
5
所有与k不互质的数的贡献就是p1的倍数的贡献+p2的倍数的贡献+...+pu的倍数的贡献-p1*p2的倍数的贡献-p1*p3的倍数的贡献-...+p1*p2*p3的倍数的贡献+......

以p1的倍数的贡献为例,他的贡献是(p1*)^+(p1*)^+...+(p1*[k/p1])^2,就是p^2*(1^2+2^2+...+(p1*[k/p1])^2

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e4+;
const int p=;
int T,cnt,k;
bool vis[N];
int prime[N],a[N];
void pre()
{
for (int i=;i<N;i++)
{
if (!vis[i]) prime[++cnt]=i;
for (int j=;j<=cnt&&prime[j]*i<N;j++)
{
vis[prime[j]*i]=;
if (i%prime[j]==) break;
} }
}
ll poww(ll x,int y)
{
ll ret=;
while (y)
{
if (y&) ret=ret*x%p;
x=x*x%p;
y>>=;
}
return ret;
}
int fund(int n)
{
int sum=;
for (int i=;i<=cnt;i++)
{
if (prime[i]>n) break; if (n%prime[i]==)
{
a[sum++]=prime[i];
while (n%prime[i]==) n/=prime[i];
}
}
if (n>) a[sum++]=n;
return sum;
}
void solve(int n)
{
ll nn=(ll)n;
ll inv6=poww(,p-);
ll ans=nn%p*(nn+)%p*(*nn+)%p*inv6%p; int sum=fund(n); ll tmp=;
for (int i=;i<(<<sum);i++)
{
ll x=;int s=;
for (int j=;j<sum;j++)
{
if ((i>>j)&)
{
x=x*(ll)a[j]%p;
s++;
}
} ll t=(ll)n/x;
if (s&) tmp=(tmp+x*x%p*t%p*(t+)%p*(*t+)%p*inv6%p)%p;
else tmp=((tmp-x*x%p*t%p*(t+)%p*(*t+)%p*inv6%p)%p+p)%p; } ans=((ans-tmp)%p+p)%p; printf("%lld\n",ans);
}
int main()
{
pre();
scanf("%d",&T);
while (T--)
{
scanf("%d",&k);
solve(k);
}
return ;
}
 

ICPC2017 Urumqi - K - Sum of the Line的更多相关文章

  1. summary of k Sum problem and solutions in leetcode

    I found summary of k Sum problem and solutions in leetcode on the Internet. http://www.sigmainfy.com ...

  2. lintcode: k Sum 解题报告

    K SUM My Submissions http://www.lintcode.com/en/problem/k-sum/ 题目来自九章算法 13% Accepted Given n distinc ...

  3. k Sum | & ||

    k Sum Given n distinct positive integers, integer k (k <= n) and a number target. Find k numbers ...

  4. 求和问题总结(leetcode 2Sum, 3Sum, 4Sum, K Sum)

    转自  http://tech-wonderland.net/blog/summary-of-ksum-problems.html 前言: 做过leetcode的人都知道, 里面有2sum, 3sum ...

  5. K Sum(2 Sum,3 Sum,4 Sum,3-Sum Closest)

    算是经典算法问题了.这里主要针对只存在一个解或者只需要求一个解的情况描述一下解题思路.若需要找到所有可能解,方法需要略作调整.如有问题,欢迎指正. 2 sum: 如果已排序,可直接用夹逼法,即两指针从 ...

  6. LeetCode解题报告--2Sum, 3Sum, 4Sum, K Sum求和问题总结

    前言: 这几天在做LeetCode 里面有2sum, 3sum(closest), 4sum等问题, 这类问题是典型的递归思路解题.该这类问题的关键在于,在进行求和求解前,要先排序Arrays.sor ...

  7. 2019年南京网络赛E题K Sum(莫比乌斯反演+杜教筛+欧拉降幂)

    目录 题目链接 思路 代码 题目链接 传送门 思路 首先我们将原式化简: \[ \begin{aligned} &\sum\limits_{l_1=1}^{n}\sum\limits_{l_2 ...

  8. 南京网络赛 E K Sum

    K Sum 终于过了这玩意啊啊啊==== 莫比乌斯反演,杜教筛,各种分块,积性函数怎么线性递推还很迷==,得继续研究研究 #include<bits/stdc++.h> using nam ...

  9. 2019南京网络赛E:K Sum

    Description: 定义函数 \[ f _n (k) = \sum _{l _1 = 1} ^n \sum _{l _2 = 1} ^n \cdots \sum _{l _k = 1} ^n \ ...

随机推荐

  1. [leetcode-738-Monotone Increasing Digits]

    Given a non-negative integer N, find the largest number that is less than or equal to N with monoton ...

  2. ZOJ 2760 How Many Shortest Path(最短路径+最大流)

    Description Given a weighted directed graph, we define the shortest path as the path who has the sma ...

  3. 自测之Lesson8:进程操作

    题目:请解释wait是如何同步父子进程的. 程序代码: #include <stdio.h> #include <unistd.h> #include <sys/type ...

  4. JavaScript初探系列之面向对象

    面向对象的语言有一个标志,即拥有类的概念,抽象实例对象的公共属性与方法,基于类可以创建任意多个实例对象,一般具有封装.继承.多态的特性!但JS中对象与纯面向对象语言中的对象是不同的,ECMA标准定义J ...

  5. 算法与数据结构5.1 Just Sort

    ★实验任务 给定两个序列 a b,序列 a 原先是一个单调递增的正数序列,但是由于某些 原因,使得序列乱序了,并且一些数丢失了(用 0 表示).经过数据恢复后,找 到了正数序列 b ,且序列 a 中 ...

  6. PAT1024 强行用链表写了一发。

    主要的思想还是 上课的那个PPT上面的 链表反转的思想. 然后加一点七七八八的 递推. 一层一层往下翻转就好啦. 1A 真开心. 代码:http://paste.ubuntu.net/16506799 ...

  7. 什么是POJO模式

    1.     什么是POJO POJO的名称有多种,pure old java object .plain ordinary java object 等. 按照Martin Fowler的解释是“Pl ...

  8. 【nginx】nginx:利用负载均衡原理实现代码的热部署和灰度发布

    事情起因很简单,代码的改动量很大.而且刚接手服务器,对原有的代码进行了一定程度的重构.虽然在测试服务器上做了较多的测试工作,但是直接将代码送入生产环境还是不放心,万一配置出问题服务直接崩溃怎么解?万一 ...

  9. BZOJ 1898 沼泽鳄鱼(矩阵快速幂)

    没有食人鱼不是裸题吗,用一个向量表示从s到1..N的距离,然后不停乘邻接矩阵行了,当然快速幂 有食人鱼,发现食人鱼最多十二个邻接矩阵一循环,处理出12个作为1个然后快速幂行了   怎么处理呢? 假设食 ...

  10. 【bzoj4736/uoj#274】[清华集训2016]温暖会指引我们前行 语文题+LCT

    题目描述 http://uoj.ac/problem/274 题解 语文题+LCT 对于这种语文题建议还是自己读题好一些... 读懂题后发现:由于温度互不相同,最大生成树上的路径必须走(不走的话温度大 ...