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=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;
}
2017乌鲁木齐ICPC: K. Sum of the Line(容斥)相关推荐
- ACM-ICPC 2017 Asia Urumqi K. Sum of the Line 容斥
5222: Sum of the Line 时间限制: 1 Sec 内存限制: 128 MB 提交: 203 解决: 59 [提交] [状态] [讨论版] [命题人:admin] 题目描述 Con ...
- NYOJ 762 第k个互质数(二分 + 容斥)
第k个互质数 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 两个数的a,b的gcd为1,即a,b互质,现在给你一个数m,你知道与它互质的第k个数是多少吗?与m互质的数按 ...
- 2017乌鲁木齐ICPC: I. A Possible Tree(带权并查集)
I. A Possible Tree Alice knows that Bob has a secret tree (in terms of graph theory) with n nodes wi ...
- UPC5222 Sum of the Line(分解质因数+容斥原理)
链接:http://exam.upc.edu.cn/problem.php?cid=1299&pid=10 问题 K: Sum of the Line 时间限制: 1 Sec 内存限制: 1 ...
- Sum of the Line UPC5222 (容斥)
莫过一日曝十日寒. 5222: Sum of the Line 时间限制: 1 Sec 内存限制: 128 MB 提交: 212 解决: 61 [提交] [状态] [讨论版] [命题人:admin ...
- 2017 ACM ICPC Asia Regional - Daejeon
2017 ACM ICPC Asia Regional - Daejeon Problem A Broadcast Stations 题目描述:给出一棵树,每一个点有一个辐射距离\(p_i\)(待确定 ...
- 2017年ICPC西安邀请赛A、XOR(线段树套线性基 + 思维)
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 题目传送门 Problem 给你 nnn 和 nnn 个整数的数组 aaa,以及kkk和qqq,有 q ...
- lintcode: k Sum 解题报告
K SUM My Submissions http://www.lintcode.com/en/problem/k-sum/ 题目来自九章算法 13% Accepted Given n distinc ...
- 2019-ACM-ICPC-南京区网络赛-E. K Sum(莫比乌斯反演 + 杜教筛)
K Sum 推式子 Fn(k)=∑l1=1n∑l2=1n⋯∑lk=1n(gcd(l1,l2,-,lk))2=∑d=1nd2∑l1=1nd∑l2=1nd⋯∑lk=1nd(gcd(l1,l2,-,lk)= ...
最新文章
- 互联网黄金十年的黄昏——是人工智能的黎明还是裁员的长夜
- 还不知道BeanFactory和ApplicationContext的区别?
- ajax中的async
- NHibernate之旅(7):初探NHibernate中的并发控制
- 使用 CNF 测试套件测试云原生最佳实践
- java----EL表达式
- 关于值传递和指针传递
- [转帖]Windows下cwRsyncServer双机连续同步部署
- FlashBuilder使用
- 例外被抛出且未被接住--服务端与客户端隐藏
- 飞算soflu软件机器人-低代码的未来
- 如何在游戏中设置游戏的帧率和显示帧率
- 什么是Linux ,Unix和Linux有什么区别
- 2018 最新注册码【激活码】、在线激活 pycharm 完整方法(亲测有效)【2018.05.08 重大更新!!!!】
- 启航——我的第一篇博客
- php时间戳,日期时间转换及使用大全
- 我吃的肉里都有量子力学了?
- 让流媒体服务SRS支持P2P通信
- 树形结构(Python)
- JIRA Core、JIRA Software、JIRA Service Desk的区别
热门文章
- python3.6.5安装步骤-Ubuntu16.04安装python3.6.5步骤详解
- 2020年,为什么你该学PHP?!!
- python数据科学手册_数据科学的Python
- 3700打印机和计算机连接,WNDR3700成功实现打印机服务器功能(刷机成WNDR3800)
- 【深度优先搜索】计蒜客:引爆炸弹
- flink sql设置并行度_Flink原理——任务调度原理
- 鼎微方案导航一体机刷机包_SMB方案之星 | 海康威视人脸门禁一体机产品应用方案集锦...
- h264解码延迟优化_JEET Air Plus:延迟优化技术,让你游戏不掉线
- 完全卸载Oracle11
- jdk版本低于1.7 waterdrop 打不开解决