2017多校第4场 HDU 6069 Counting Divisors 素筛,暴力,优化
来源:互联网 发布:高德导航软件 编辑:程序博客网 时间:2024/06/03 18:38
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6069
题意:求题目中给出的式子。
解法:
#include <bits/stdc++.h>using namespace std;typedef long long LL;const int maxn = 1e6+10;const int mod = 998244353;LL l, r, v[maxn], ans[maxn];int prime[maxn],k,tot;bool isprime[maxn];void init(){ tot=0; memset(isprime,1,sizeof(isprime)); for(int i=2; i<maxn; i++){ if(isprime[i]) for(LL j=(LL)i*i; j<maxn; j+=i) isprime[j]=0; } for(int i=2; i<maxn; i++) if(isprime[i]) prime[++tot] = i;}void work(LL p){ LL st=l/p*p; if(st!=l)st+=p; LL en=r/p*p; for(LL i=st;i<=en; i+=p){ int cnt=0; while(v[i-l]%p==0){ cnt++; v[i-l]/=p; } ans[i-l]*=k*cnt+1; ans[i-l]%=mod; }}int main(){ init(); int T; scanf("%d",&T); while(T--){ scanf("%lld%lld%d",&l,&r,&k); for(LL i=l; i<=r; i++){ v[i-l]=i; ans[i-l]=1; } for(int i=1; i<=tot; i++){ work(prime[i]); } LL sum=0; for(LL i=l; i<=r; i++){ if(v[i-l]>1){ ans[i-l]*=k+1; } sum+=ans[i-l]; sum%=mod; } printf("%lld\n", sum); } return 0;}
阅读全文
0 0
- 2017多校第4场 HDU 6069 Counting Divisors 素筛,暴力,优化
- 2017 多校训练第四场 HDU 6069 Counting Divisors
- hdu 6069 Counting Divisors(2017多校第四场)
- Hdu6069 Counting Divisors(2017多校第4场)
- HDU 6069 Counting Divisors 多校联合第四场
- hdu 6069 Counting Divisors
- [HDU]6069 Counting Divisors
- HDU 6069 Counting Divisors
- HDU 6069 Counting Divisors
- HDU-6069 Counting Divisors
- HDU 6069 Counting Divisors
- HDU-6069 Counting Divisors
- HDU 6069 Counting Divisors
- HDU 6069 Counting Divisors
- hdu 6069 Counting Divisors
- HDU 6069 Counting Divisors
- hdu--6069--Counting Divisors
- HDU-6069 Counting Divisors
- Linux -bash: java: command not found 解决方法
- HDU 2689 Sort it 树状数组
- 【PAT】【Advanced Level】1039. Course List for Student (25)
- 【算法基础】算法导论-最大子数组问题
- Docker 编排利器-Compose简介
- 2017多校第4场 HDU 6069 Counting Divisors 素筛,暴力,优化
- java静态代码块 构造代码块 构造方法的执行顺序及注意问题
- 二叉树
- Python日常学习记录
- 装饰器
- JS日期,其他对象
- 拼多多笔试题:大数据乘法
- 【HDU-1863】 畅通工程
- JSON详解