多校
来源:互联网 发布:手机画板软件 编辑:程序博客网 时间:2024/06/05 07:04
Counting Divisors
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 1286 Accepted Submission(s): 454
Problem Description
In mathematics, the function d(n) denotes the number of divisors of positive integer n .
For example,d(12)=6 because 1,2,3,4,6,12 are all 12 's divisors.
In this problem, givenl,r and k , your task is to calculate the following thing :
(∑i=lrd(ik))mod998244353
For example,
In this problem, given
Input
The first line of the input contains an integer T(1≤T≤15) , denoting the number of test cases.
In each test case, there are3 integers l,r,k(1≤l≤r≤1012,r−l≤106,1≤k≤107) .
In each test case, there are
Output
For each test case, print a single line containing an integer, denoting the answer.
Sample Input
31 5 11 10 21 100 3
Sample Output
10482302
Source
2017 Multi-University Training Contest - Team 4
自己写的代码:
#include<cstdio>typedef long long ll;const int N=1000010,P=998244353;int Case,i,j,k,p[N/10],tot,g[N],ans;ll n,l,r,f[N];bool v[N];inline void work(ll p){ for(ll i=l/p*p; i<=r; i+=p)if(i>=l) { int o=0; while(f[i-l]%p==0)f[i-l]/=p,o++; g[i-l]=1LL*g[i-l]*(o*k+1)%P; }}int main(){ for(i=2; i<N; i++) { if(!v[i])p[tot++]=i; for(j=0; j<tot&&i*p[j]<N; j++) { v[i*p[j]]=1; if(i%p[j]==0)break; } }// 素数筛法 scanf("%d",&Case); while(Case--) { scanf("%lld%lld%d",&l,&r,&k); n=r-l; for(i=0; i<=n; i++)f[i]=i+l,g[i]=1; for(i=0; i<tot; i++) { if(1LL*p[i]*p[i]>r)break; work(p[i]); } for(ans=i=0; i<=n; i++) { if(f[i]>1)g[i]=1LL*g[i]*(k+1)%P; ans=(ans+g[i])%P; } printf("%d\n",ans); } return 0;}
显然服务器只要稍微一不高兴,就给你卡了。
陈老师的代码:
#include<cstdio>typedef long long ll;const int N=1000010,P=998244353;int Case,i,j,k,p[N/10],tot,g[N],ans;ll n,l,r,f[N];bool v[N];inline void work(ll p){ for(ll i=l/p*p; i<=r; i+=p)if(i>=l) { int o=0; while(f[i-l]%p==0)f[i-l]/=p,o++; g[i-l]=1LL*g[i-l]*(o*k+1)%P; }}int main(){ for(i=2; i<N; i++) { if(!v[i])p[tot++]=i; for(j=0; j<tot&&i*p[j]<N; j++) { v[i*p[j]]=1; if(i%p[j]==0)break; } }// 素数筛法 scanf("%d",&Case); while(Case--) { scanf("%lld%lld%d",&l,&r,&k); n=r-l; for(i=0; i<=n; i++)f[i]=i+l,g[i]=1; for(i=0; i<tot; i++) { if(1LL*p[i]*p[i]>r)break; work(p[i]); } for(ans=i=0; i<=n; i++) { if(f[i]>1)g[i]=1LL*g[i]*(k+1)%P; ans=(ans+g[i])%P; } printf("%d\n",ans); } return 0;}
无论怎么卡也可以过。这个就是实现问题吧。
阅读全文
0 0
- 多校
- 多校
- 多校
- HDU4869 多校
- hdu5288 多校
- hdu5288 多校
- 多校3
- hdu 多校
- hdu 多校
- 多校 hdu
- 多校 hdu
- 多校 hdu
- HDU 多校
- 多校 9
- 多校 GCD
- 多校10
- 17 多校
- 17 多校
- 自动代理
- Spring-jdbc实现查询和事务的实现
- 119_容器_自定义实现迭代器_深入迭代器_迭代器原理_面向对象实现
- vue2.0子组件调用父组件的数据
- 关于next_permutation
- 多校
- 展讯9832A DDR3不能开机
- 散射表(哈希表)解决冲突的两种办法
- 120_容器_HashMap_经典存储_分拣思路
- CodeForces 9C Hexadecimal's Numbers
- 121_容器_HashMap_经典存储_经典分拣思路_与面向对象组合解题
- Java三大框架SSH的各自作用
- 仿ios开关
- Spring Aspectj 代理 前置 后置 以及 异常