HDU 6069 Counting Divisors -质因子个数-2017多校联盟4 第3题
来源:互联网 发布:ubuntu 命令不提示 编辑:程序博客网 时间:2024/06/08 08:09
Counting Divisors
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 1712 Accepted Submission(s): 623
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
/*题意:计算Σd(i^k),i∈[l,r],d(x)表示x的因子的个数题解:1.求一个数的因子个数方法:分解质因数,质因数的指数+1再相乘例如42 = 2^2*3^1*7^1;则因数个数为:(2+1)*(1+1)*(1+1) = 12而 x^k = (p1^x1 * p2^x2 * ……)^k = p1^(x1*k) * p2^(x2*k) * ……例如 42^2 = 2^4 * 3^2 * 7^2 则因数个数为(4+1)*(2+1)*(2+1) = 452.这样如果枚举每个i 会超时。我们选择枚举每个质数。分解质因数时,质数枚举到 根r 以内就够了对于区间l到r内的数,只要能除开质数p[i]的,就分解,详见代码*/#include <iostream>#include <cstdio>#include <cstring>using namespace std;typedef long long ll;const int maxn = 1000000+10;const ll mod = 998244353;ll g[maxn];///g[i]表示数i+l有多少个因子ll f[maxn];///f[i]表示第i个数是i+l,f[i]数组用来分解质因数ll p[maxn];bool vis[maxn];int main(){ ///处理根r以内的素数 int total = 0; for(int i = 2;i<maxn;++i){ if(!vis[i]){///非偶 p[++total] = i; } for(int j = 1;j<=total && p[j]*i<maxn;++j){ vis[i*p[j]] = 1; if(i%p[j]==0) break; } } int t; scanf("%d",&t); while(t--){ ll l,r,k; scanf("%lld%lld%lld",&l,&r,&k); for(ll i = 0;i<r-l+1;++i){///映射,把l~r映射到从下标0~r-l f[i] = i+l; g[i] = 1; } for(ll i = 1;i<=total && p[i]*p[i]<=r;++i){///枚举根r以内的素数就够了 for(ll j = l/p[i]*p[i];j<=r;j+=p[i]){///枚举属于l~r之间的p[i]的倍数 if(j<l) continue;///l/p[i]*p[i] 可能是小于l(字母L)的数或者是l int cnt = 0; while(f[j-l]%p[i] == 0){ f[j-l]/=p[i]; cnt++; } g[j-l] = (g[j-l]*(cnt*k+1))%mod; } } ll ans = 0; for(int i = 0;i<r-l+1;++i){ if(f[i]>1){///说明这个数没有被除完,这个数是个质因子 g[i] = g[i]*(1*k+1) % mod; } ans = (ans+g[i])%mod; } printf("%lld\n",ans); } return 0;}
阅读全文
1 0
- HDU 6069 Counting Divisors -质因子个数-2017多校联盟4 第3题
- HDU 6069 Counting Divisors(求因子)
- HDU 6069 Counting Divisors 【2017多校联赛4】
- HDU 6069 Counting Divisors (约数个数定理)
- HDU 6069 Counting Divisors【约数个数定理】
- hdu 6069 Counting Divisors(2017多校第四场)
- 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
- source insight 4 破解版可用
- Python3 异常处理
- 素数筛法打表
- linux下root用户以及非root用户忘记密码的解决方案
- CodeForces
- HDU 6069 Counting Divisors -质因子个数-2017多校联盟4 第3题
- 万维链的原生币万维币在万维链上线后有什么作用?
- 最全Pycharm教程(3)——代码的调试、运行
- Android中常见的面试题总结(一)
- HTML中滚动条属性相关设置
- Android 使用CDM查看信息
- js常用正则表达式(二)
- Django多进程日志文件问题
- Python中函数的参数定义和可变参数