【hdu 6069】 Counting Divisors 【思维+数论】
来源:互联网 发布:python 爬虫库推荐 编辑:程序博客网 时间:2024/06/06 00:28
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, given l,r and k, your task is to calculate the following thing :
(∑i=lrd(ik))mod998244353
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
3
1 5 1
1 10 2
1 100 3
Sample Output
10
48
2302
Source
2017 Multi-University Training Contest - Team 4
分析
1>首先明确 一个数的因数个数为多少 :
因为 n=p1^r1*p2^r2….pn^rn ;所以 因子个数为(r1+1)(r2+1)(rn+1) , 其k次方的因子个数为(r1*k+1)(r2*k+1)(rn*k+1) ,所以我们就要找素数来解。
2>剩下的不好描述看代码吧。
代码
#include<bits/stdc++.h>#define LL long longusing namespace std;const int MAXN = 1e6+500; const int MAXM = 1e5;const LL mod =998244353;bool su[MAXN];int prm[MAXN],sz=0;void init(){ // 这个素筛还是快一些 for(int i=2;i<MAXN;++i){ if(!su[i]) prm[sz++]=i; for(int j=0;j<sz;++j){ int t=i*prm[j]; if(t>=MAXN) break; su[t]=1; if(i%prm[j]==0) break; } }}LL arr[MAXN],ans[MAXN];LL size;void solve(LL l,LL r,LL k){ for(LL i=0;i<sz;i++){ LL pos=(l+prm[i]-1)/prm[i]*prm[i]; // 这里通过计算可以求得 大于l的最小的可以被prm[i]整除的数字 pos-=l;//得到位置 while(pos<size){// 遍历区间,将prm[i]的倍数都筛掉 LL cnt=0; while(arr[pos]%prm[i]==0) { cnt++; arr[pos]/=prm[i];} ans[pos]=(ans[pos]*(cnt*k%mod+1))%mod;//更新个数 pos+=prm[i];//优化,不断的加prm[i]一定是其倍数 } }// puts("---------"); LL sum=0; for(LL i=0;i<size;i++){ if(arr[i]==1) ;// 说明这个数字可以被完全分解为1-1e6之内的素数 //否则就说明 其剩下的一定是 一个素数,且次幂为1 else ans[i]=(ans[i]*(1*k%mod+1))%mod; sum=(sum+ans[i])%mod; } printf("%lld\n",sum%mod);}int main(){ init(); int t;cin>>t; while(t--){ LL l,r,k; scanf("%lld%lld%lld",&l,&r,&k); size=0; for(LL i=l;i<=r;i++) { ans[size]=1; arr[size++]=i; } solve(l,r,k); } 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
- 组合数求模
- Linux检测IP地址冲突
- Navigation Nightmare poj 1984
- lua中__call元方法
- Python面试题
- 【hdu 6069】 Counting Divisors 【思维+数论】
- C
- 限制用户输入 正则表达式 去除中文 中文符号
- 笔记16--Js基础知识--日期和其他对象
- hdu 3183 A Magic Lamp (贪心 or RMQ)
- 教你关闭一个不活动的或者空闲的SSH会话
- bash脚本运行出现未知错误
- JavaScript进阶:谈谈对闭包的理解
- ThreadPool 之 线程池工具类 Executors