HDU 6069 Counting Divisors 【数论】
来源:互联网 发布:淘宝客服有提成吗 编辑:程序博客网 时间:2024/06/02 06:56
Counting Divisors
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 2927 Accepted Submission(s): 1074
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
Recommend
liuyiding | We have carefully selected several similar problems for you: 6084 6083 6082 6081 6080
思路:知道约束定理后就可以很容易的处理k。
枚举质因数,再类似筛法,累计每个数。
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<queue>#include<stack>#include<vector>#include<map>#include<set>#include<algorithm>using namespace std;#define ll long long#define ms(a,b) memset(a,b,sizeof(a))#define maxn 510const int M=1e6+10;const int MM=2e3+10;const int inf=0x3f3f3f3f;const int mod=998244353;const double eps=1e-10;ll r,l,k;ll cnt[M];int sum;ll ans[M];ll a[M];ll vis[M];void prime(){ sum=0;int q=1e6+10; ms(vis,0); for(int i=2;i<=q;i++){ if(!vis[i]){ cnt[sum++]=i; for(int j=i+i;j<=q;j+=i)vis[j]=1; } }}int main(){ int t; prime(); scanf("%d",&t); while(t--){ scanf("%lld%lld%lld",&l,&r,&k); for(int i=1;i<=r-l+1;i++){ ans[i]=1; a[i]=l-1+i; } for(int i=0;i<sum&&cnt[i]<=r;i++){ ll kk=l/cnt[i]; ll p=kk*cnt[i]; if(p<l)p+=cnt[i]; for(;p<=r;p+=cnt[i]){ int xx=0; ll pp=p; int pos=p-l+1; while(pp%cnt[i]==0){ xx++; pp/=cnt[i]; a[pos]/=cnt[i]; } ll nn=ans[pos];nn*=(xx*k+1)%mod;nn%=mod; ans[pos]=nn; } } ll res=0; for(int i=1;i<=r-l+1;i++){ if(a[i]!=1){ ll nn=k+1;nn*=ans[i]%mod;nn%=mod; ans[i]=nn; } res+=ans[i]; res%=mod; } printf("%lld\n",res); } return 0;}
阅读全文
0 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
- Centos6.5下guacamole 0.9.8配置数据库,实现管理多台电脑
- 【Druid】Access Denied for User ''@'ip'
- itoa函数 和_itoa_s函数
- 从Java文件到字节码文件
- CentOS安装memcached
- HDU 6069 Counting Divisors 【数论】
- 基础算法之三 希尔排序的实现
- 安卓,网页控件,显示网页 Android, web controls, display web pages
- 某个概念
- spring 国际化 java.lang.IllegalArgumentException: Malformed \uxxxx encoding
- 链式队列
- margin属性的正负值确定
- 2017"百度之星"程序设计大赛-资格赛-1002-度度熊的王国战略
- SPOJ