HDU 6069 Counting Divisors (约数个数定理)
来源:互联网 发布:如何做一名程序员 编辑:程序博客网 时间:2024/05/16 10:07
Counting Divisors
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 1269 Accepted Submission(s): 446
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
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6069
题目分析:根据约数个数定理,d(i^k) = (kc1 + 1) * (kc2 + 1) * ... * (kcj + 1),其中i = p1^c1*p2^c2*...*pj^cj,容易想到枚举每个素数对区间每个数字的贡献值(即幂指数),素数只需枚举到sqrt(r),最多只有7万多个,大于sqrt(r)部分的幂指数不会超过1,计算答案的时候如果存在大于sqrt(r)的素约数,直接乘一个(k + 1)即可。
import java.util.*;public class Main { public static final int MAX = 100005; public static final int MAXP = 1000005; public static final int MOD = 998244353; public static int pnum = 0, n; public static Scanner in = new Scanner(System.in); public static long l, r, k; public static boolean[] noprime = new boolean[MAXP]; public static int p[] = new int[MAX]; public static long a[] = new long[MAXP]; public static long num[] = new long[MAXP]; public static void getPrime() { for (int i = 2; i < MAXP; i ++) { if (!noprime[i]) { p[pnum ++] = i; } for (int j = 0; j < pnum && i * p[j] < MAXP; j ++) { noprime[i * p[j]] = true; if (i % p[j] == 0) { break; } } } } public static long cal(long l, long r, long k) { long ans = 0; for (long i = l; i <= r; i ++) { int idx = new Long(i - l).intValue(); a[idx] = 1; num[idx] = i; } for (int i = 0; i < pnum && p[i] * p[i] <= r; i ++) { long val = (l + p[i] - 1) / p[i] * p[i]; for (; val <= r; val += p[i]) { int cnt = 0, idx = new Long(val - l).intValue(); while (num[idx] % p[i] == 0) { num[idx] /= p[i]; cnt ++; } a[idx] = (a[idx] * (k * cnt + 1)) % MOD; } } for (long val = l; val <= r; val ++) { int idx = new Long(val - l).intValue(); ans = (num[idx] == 1) ? (ans + a[idx]) % MOD : (ans + a[idx] * (k + 1)) % MOD; } return ans; } public static void main(String[] args) { getPrime(); n = in.nextInt(); for (int ca = 1; ca <= n; ca ++) { l = in.nextLong(); r = in.nextLong(); k = in.nextLong(); System.out.println(cal(l, r, k)); } }}
阅读全文
0 0
- HDU 6069 Counting Divisors (约数个数定理)
- HDU 6069 Counting Divisors【约数个数定理】
- HDU 6069 Counting Divisors【素数筛】【约数个数定理】
- HDU6069-Counting Divisors(约数个数定理)
- HDU6069-Counting Divisors 约数个数定理+素数分解
- hdu 6069 Counting Divisors(约数个数)(2017 Multi-University Training Contest
- hud 6069 Counting Divisors(数学题 约数定理)
- hdu6069Counting 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系统yum安装软件(一)
- 2-19分区、swap、raid
- IDEA快捷键使用
- centos 7 sogou input
- 倒角距离变换
- HDU 6069 Counting Divisors (约数个数定理)
- mybatis中的#和$的区别
- 【LeetCode】001. Two Sum
- P1269 马棚
- PAT乙级 1034
- 倒角距离匹配
- 暑期ssh框架之struts2学习笔记二
- 基于光流的视频语义分割和物体检测
- Eclipse-EE查看classes文件