ICPC2017 Urumqi - K - Sum of the Line
题目描述
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.
输入
Each test case includes a single line with an integer k described as above satisfying 2 ≤ k ≤ 10^8 .
输出
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的更多相关文章
- 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 ...
- lintcode: k Sum 解题报告
K SUM My Submissions http://www.lintcode.com/en/problem/k-sum/ 题目来自九章算法 13% Accepted Given n distinc ...
- k Sum | & ||
k Sum Given n distinct positive integers, integer k (k <= n) and a number target. Find k numbers ...
- 求和问题总结(leetcode 2Sum, 3Sum, 4Sum, K Sum)
转自 http://tech-wonderland.net/blog/summary-of-ksum-problems.html 前言: 做过leetcode的人都知道, 里面有2sum, 3sum ...
- K Sum(2 Sum,3 Sum,4 Sum,3-Sum Closest)
算是经典算法问题了.这里主要针对只存在一个解或者只需要求一个解的情况描述一下解题思路.若需要找到所有可能解,方法需要略作调整.如有问题,欢迎指正. 2 sum: 如果已排序,可直接用夹逼法,即两指针从 ...
- LeetCode解题报告--2Sum, 3Sum, 4Sum, K Sum求和问题总结
前言: 这几天在做LeetCode 里面有2sum, 3sum(closest), 4sum等问题, 这类问题是典型的递归思路解题.该这类问题的关键在于,在进行求和求解前,要先排序Arrays.sor ...
- 2019年南京网络赛E题K Sum(莫比乌斯反演+杜教筛+欧拉降幂)
目录 题目链接 思路 代码 题目链接 传送门 思路 首先我们将原式化简: \[ \begin{aligned} &\sum\limits_{l_1=1}^{n}\sum\limits_{l_2 ...
- 南京网络赛 E K Sum
K Sum 终于过了这玩意啊啊啊==== 莫比乌斯反演,杜教筛,各种分块,积性函数怎么线性递推还很迷==,得继续研究研究 #include<bits/stdc++.h> using nam ...
- 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.编译azkaban
1.下载azkaban的源码 https://github.com/azkaban/azkaban.git 然后解压得到azkaban-master.zip,解压:unzip azkaban-mast ...
- Centos6更新yum repo
163开源镜像站是国内比较老的一个网站.很多人都在使用. step 1/3 备份原镜像文件: cd /etc/yum.repos.d mv CentOS-Base.repo CentOS-Base.r ...
- HDU 4302 Holedox Eating (线段树模拟)
题意:一个老鼠在一条长度为L的直线上跑,吃蛋糕,老鼠只能沿直线移动.开始时没有蛋糕,老鼠的初始位置是0. 有两个操作,0 x 代表在位置x添加一个蛋糕: 1 代表老鼠想吃蛋糕.老鼠每次都会选择离自己最 ...
- 自测之Lesson13:共享内存
题目:创建一个64K的共享内存. 实现代码: #include <stdio.h> #include <sys/ipc.h> #include <sys/shm.h> ...
- Java常用类之Math类
Java 的常用类Math类: java.lang.Math 提供了系列的静态方法用于科学计算,其方法的参数和返回值类型一般为 double 类型. 如: 1. public static final ...
- ASP.NET 使用MVC4的EF5 Code First 入门(一):创建数据库
一.基本流程 建立模型→建立控制器→EF框架自动生成视图的数据库 二.基本理论 1.约定优于配置(Convention Over Configuration) 设计不好的框架通常需要多个配置文件,每一 ...
- VS2012或VS2010 工具栏中无法显示DevExpress控件
进入命令提示符 跳转到Dev控件安装目录,如[目录D:\Program Files (x86)\DevExpress\DXperience 12.2\Tools]下, 然后执行命令: ToolboxC ...
- Qt语言家(Qt Linguist)更新翻译报错-Qt5.9-MinGW
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt语言家(Qt Linguist)更新翻译报错-Qt5.9-MinGW 本文地址:h ...
- HDU 2133 What day is it
http://acm.hdu.edu.cn/showproblem.php?pid=2133 Problem Description Today is Saturday, 17th Nov,2007. ...
- 限制玻尔兹曼机(Restricted Boltzmann Machine)RBM
假设有一个二部图,每一层的节点之间没有连接,一层是可视层,即输入数据是(v),一层是隐藏层(h),如果假设所有的节点都是随机二值变量节点(只能取0或者1值)同时假设全概率分布满足Boltzmann 分 ...
