HDU 6069 数学题,区间素数筛
来源:互联网 发布:股票同花顺软件下载 编辑:程序博客网 时间:2024/06/05 19:05
Counting Divisors
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 691 Accepted Submission(s): 227
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
题意 要你输入 一个区间 l r k 要你算上式,对于求因子数 d(n) , n = (p1^c1*p2^c2...) 其中pi 为质因子,则 d(n) = (c1 + 1) * (c2 + 1) +... + (ci + 1)
而题目要求 d(n^k) = (k * c1 + 1) + (k * c2 + 1) + ... +(k * ci + 1) 所以只要求出这个 n 的质因子就可以了
由于数开的非常大,开到了 10e12,所以一般正常地打素数表是会炸的,于是用到了 区间素数筛
区间素数筛: 对于 n 以内的素数 ,只要筛出了 根号(x)以内的素数就可以筛出x以内的素数 所以对于10e12的n只需要打1e6就可以了,时间复杂度就降下来了
然后题目说 l 和 r 之间的差值不会10e6 所以数组开10e6就可以了,然后在使用的时候用 pos - l 就可以了
然后从离l最近的素数开始去计算值就可以了
#include<stdio.h>#define ll long long#define mod 998244353#define MAXN 1000500bool p[MAXN];ll prm[MAXN];ll n;ll arr[MAXN],d[MAXN]; void init(){ //区间素数筛 for(ll i = 2;i < MAXN;i++){if(!p[i]){prm[n++] = i;}for(int j = 0;j < n;j++){ll t = i * prm[j];if(t >= MAXN){break;}p[t] = true;if(i % prm[j] == 0)break;}}}ll work(ll l,ll r,ll k){for(int i = 0;i < n;i++){ll pos = (l + prm[i] - 1) / prm[i] * prm[i];while(pos <= r){ll cnt = 0;while(arr[pos - l] % prm[i] == 0){cnt++;arr[pos - l] /= prm[i];}d[pos - l] *= (k * cnt + 1);d[pos - l] %= mod;pos += prm[i];}}ll sum = 0;for(ll pos = l;pos <= r;pos++){if(arr[pos - l] == 1){sum += d[pos - l];}else{sum += d[pos - l] * (k + 1);}sum %= mod;}return sum;}int main(){init();int t;ll l,r,k;scanf("%d",&t);while(t--){scanf("%lld %lld %lld",&l,&r,&k);for(ll i = l;i <= r;i++){d[i - l] = 1;arr[i - l] = i;}ll ans = work(l,r,k);printf("%lld\n",ans);}return 0;}
阅读全文
1 0
- HDU 6069 数学题,区间素数筛
- HDU 6069 数论 区间素数筛(+赛后反思
- HDU 6069 Counting Divisors(枚举区间)(素数筛模版)
- 素数表,区间素数筛
- Hdu 6069 Counting Divisors【素数区间筛+预处理素因子分解】
- hdu 6069 区间筛
- hdu 6069 区间筛
- 区间素数筛模板
- 区间筛素数
- 区间素数筛
- HDU 5901 Count primes (区间素数个数)
- HDU 2521 反素数(区间反素数)
- HDU 6069(素数筛法)
- 大数区间筛素数 线性
- 洛谷p1865区间筛素数
- HDU 4777 - Rabbit Kingdom (树状数组 区间互素数)
- HDU 6069 素数筛+分解质因子
- 【HDU 6069 Counting Divisors】 + 素数筛 & 思维
- sina接口获取当前省市区
- Linux系统编程学习笔记(1)-文件的I/O操作
- 排序算法
- 默认 导航栏自适应
- ViewPager的使用和应用
- HDU 6069 数学题,区间素数筛
- 多校第四场 1003 HDU 6069 素数晒应用
- 结构体指针与函数
- 用户管理
- 数据分析:pandas分析链家网二手房信息
- Coprime
- html使用转义字符带来的问题
- 【Android】换行符(\n)在TextView中显示不正常的问题
- mysqlid进程使用了相同的InnoDB或者使用了同一个日志