HDU 6069 素数筛+分解质因子
来源:互联网 发布:游戏租号 软件 编辑:程序博客网 时间:2024/05/20 17:06
给一个起点为l终点为r的区间,求这个区间内的数的k次方的全部因子有多少个。
设 n=p1^c1*p2^c2...,则d(n^k)=(k*c1+1)(k*c2+1)...,r-l>=1e6
先筛出10^6内的素数,再分解出[l,r]里面的质因子,大于1e6的质数直接为(k+1)个因子。
#include <bits/stdc++.h>using namespace std;#define inf 0x3f3f3f3f#define PI acos(-1.0)typedef long long ll;const int maxn=1e6+10;const ll mod=998244353;ll vis[maxn],p[maxn],a[maxn],num[maxn],ans;ll l,r,k;void solve(int pp){ for(ll i=l/pp*pp;i<=r;i+=pp) { if(i>=l) { int cnt=0; while(a[i-l]%pp==0&&a[i-l]) a[i-l]/=pp,cnt++; num[i-l]=1LL*num[i-l]*(cnt*k+1)%mod; } }}int main(){ int cnt=0; for(int i=2;i<maxn;i++) { if(!vis[i]) p[cnt++]=i; for(int j=0;j<cnt&&1LL*i*p[j]<maxn;j++) { vis[1LL*p[j]*i]=1; if(i%p[j]==0) break; } } int t; scanf("%d",&t); while(t--) { ans=0; scanf("%lld%lld%lld",&l,&r,&k); int n=r-l; for(int i=0;i<=n;i++) a[i]=i+l,num[i]=1; for(int i=0;i<cnt;i++) { if(1LL*p[i]*p[i]>r) break; solve(p[i]); } for(int i=0;i<=n;i++) { if(a[i]>1) num[i]=1LL*num[i]*(k+1)%mod; } for(int i=0;i<=n;i++) ans=(ans+num[i])%mod; printf("%lld\n",ans); } return 0;}
阅读全文
0 0
- HDU 6069 素数筛+分解质因子
- hdu-1164涮素数+质因子分解
- HDU 1333 分解素数因子
- hdu 1164 质因子分解 (筛素数模板)+ hdu 1215
- Hdu 6069 Counting Divisors【素数区间筛+预处理素因子分解】
- hdu 4139 质因子分解
- HDU 2421 质因子分解
- hdu 2421 分解质因子
- hdu 5428(分解质因子)
- 素数打表解决质因子分解
- HDU 3864 pollard_rho大数质因子分解
- HDU 1164(质因子的分解)
- hdu 5428 the factor(分解质因子)
- HDU 5428-The Factor(分解质因子)
- poj3993Not So Flat After All(筛法素数+分解质因子)
- 关于整数的质因子分解和筛素数的分析
- 筛法求素数+分解质因子+欧拉函数+求约数
- POJ1811 miller-rabin素数测试pollard-rho质因子分解
- 572. Subtree of Another Tree
- POJ 1287 Networking
- 【剑指offer】面试题57(1):和为S的数字
- 三大需求助ROS成为百度自动驾驶车载计算框架
- 机器学习笔记(3)——贝叶斯分类
- HDU 6069 素数筛+分解质因子
- 【JavaScript】js可以直接使用的鼠标经过切换图片
- 阿里云+wordpress搭建个人博客
- Numpy、Pandas和Matplotlib包基础知识
- CUDA 8.0 + Ubuntu 16.04 @ 双显卡笔记本(核显+独显)安装教程
- nginx(2):ubuntu下安装nginx依赖gcc,zlib,pcre,openssl
- ES5.4.1 命令
- 字符串函数
- 遇到的前端笔试题