HDU 6069 Counting Divisors (素数)
来源:互联网 发布:一句可爱到化的话 知乎 编辑:程序博客网 时间:2024/06/05 16:56
Description
In mathematics, the function d(n) denotes the number of divisors of positive integer n.
For example,
d(12)=6 because1,2,3,4,6,12 are all12 ‘s divisors.In this problem, given l,r and k, your task is to calculate the following thing :
>(∑i=lrd(ik)) mod 998244353>
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 are 3 integers
l,r,k(1≤l≤r≤1012,r−l≤106,1≤k≤107) .
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
题意
给出
思路
SPOJ 中有两道类似的题目,其中一个 k = 2
,另一个 k = 3
,然后区间长度最大为
不过对于这道题来说,用不到那么高深的知识,因为区间长度只有
对于任意一个大于
另外,通过素数定理我们可以知道,任意一个正整数
同理,
于是我们考虑枚举
随后考虑每个数在
累加该区间内所有数的统计结果即为最终答案。
AC 代码
#include<bits/stdc++.h>using namespace std;typedef __int64 LL;const int maxn = 1e6+10;const int mod = 998244353;LL prime[maxn],tot;bool visit[maxn];LL l,r,k;LL num[maxn],sum[maxn];void getprime(){ tot=0; memset(visit,0,sizeof(visit)); for(int i=2; i<maxn; i++) { if(!visit[i]) { prime[tot++]=i; for(int j=i+i; j<maxn; j+=i) visit[j]=1; } }}void solve(){ for(int i=0; i<=r-l; i++) { sum[i]=1; num[i]=i+l; } for(int i=0; prime[i]*prime[i]<=r; i++) for(LL j=(l/prime[i]+(l%prime[i]?1:0))*prime[i]; j<=r; j+=prime[i]) if(j>=l) { LL res=0; while(num[j-l]%prime[i]==0) { num[j-l]/=prime[i]; res++; } sum[j-l]=sum[j-l]*(res*k+1)%mod; } LL ans=0; for(int i=0; i<=r-l; i++) { if(num[i]>1) sum[i]=sum[i]*(k+1)%mod; ans=(ans+sum[i])%mod; } cout<<ans<<endl;}int main(){ getprime(); int T; while(cin>>T) { for(int i=0; i<T; i++) { cin>>l>>r>>k; solve(); } } return 0;}
- 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
- HDU 6069 Counting Divisors
- hdu--6069--Counting Divisors
- HDU-6069 Counting Divisors
- HDU-6069 Counting Divisors
- iBatis2学习笔记:SqlMap的配置总结(18条)
- MTK Android Driver:EINT
- Linux下查看Tomcat的控制台输出信息
- Android Json数据解析的深入理解和使用
- RESTful 架构风格概述
- HDU 6069 Counting Divisors (素数)
- leetcode--Search in Rotated Sorted Array II
- maven 跳过单元测试
- 互不侵犯king
- android long数据转换成日期方法
- QT 字符串转换的一个BUG
- 行政区划代码编码规则
- first-Experience
- maven引入ojdbc