题目描述

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. SpringCloud IDEA 教学 (五) 断路器控制台(HystrixDashboard)

    写在开头 断路器控制台是为了查看断路器运行情况而研发的.本章介绍了断路器控制台的搭建,代码基于之前Client的搭建.HystrixDashboard基于之前配置好的,使用了HystrixComman ...

  2. IntelliJ IDEA 2018 for MAC安装及破解

    ---------------------说在前面-------------------------- IntelliJ IDEA 2018 版本为2018.1.4 教程按照下载安装sdk.破解两部分 ...

  3. sql 至少含有

    查询Score表中至少有5名学生选修的并以3开头的课程的平均分数: select avg(degree),cnofrom scorewhere cno like '3%'group by cnohav ...

  4. Calculator Part Ⅰ

    GitHub/object-oriented The title of the work 关于这次的作业,一开始我是觉得不难的,毕竟学长在已经提供了足够多的提示,实现步骤.需要那些方面的知识等等.但是 ...

  5. Android蓝牙开发浅谈(转)

    http://www.eoeandroid.com/thread-18993-1-1.html 对于一般的软件开发人员来说,蓝牙是很少用到的,尤其是Android的蓝牙开发,国内的例子很少     A ...

  6. Alpha-2

    前言 失心疯病源2 团队代码管理github 站立会议 队名:PMS 530雨勤(组长) 今天完成了那些任务 17:30~21:30 又测试了一些算法和代码,时间不能再拖下去了,要尽快进入代码阶段,决 ...

  7. ACM 第十五天

    计算几何基础 练习题 C - Wasted Time Mr. Scrooge, a very busy man, decided to count the time he wastes on all ...

  8. iOS如何做出炫酷的翻页效果

    详情链接http://www.jianshu.com/p/b6dc2595cc3e https://github.com/schneiderandre/popping

  9. HBase 所有命令解析

    COMMAND GROUPS:Group name: generalCommands: status, table_help, version, whoami Group name: ddlComma ...

  10. PHP中如何使用Redis接管文件存储Session详解

    https://www.jb51.net/article/151580.htm 前言 php默认使用文件存储session,如果并发量大,效率会非常低.而redis对高并发的支持非常好,可以利用red ...