HDU 6069 Counting Divisors(素数筛法+枚举+技巧)——2017 Multi-University Training Contest
来源:互联网 发布:知乎 收入 安排 编辑:程序博客网 时间:2024/05/29 10:10
传送门
Counting Divisors
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 741 Accepted Submission(s): 248
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
3
1 5 1
1 10 2
1 100 3
Sample Output
10
48
2302
题目大意:
求给定的函数值,其中
解题思路:
设有
首先预处理出
吐槽:最开始想错了,以为需要用大数分解定理,后来发现自己智障了,根本不需要。
代码:
#include <bits/stdc++.h>using namespace std;typedef long long LL;const LL MOD = 998244353;const LL MAXN=1e6+5;int prime[MAXN], cnt;LL p[MAXN];void isprime(){ memset(prime, 0, sizeof(prime)); cnt = 0; prime[1] = 1; for(LL i=2; i<MAXN; i++){ if(!prime[i]){ p[cnt++] = i; for(LL j=i*i; j<MAXN; j+=i) prime[j] = 1; } }}LL f[MAXN], num[MAXN];int main(){ isprime(); int T; scanf("%d", &T); while(T--){ LL L, R, K; scanf("%lld%lld%lld", &L, &R, &K); LL ans = 0; if(L == 1) ans = 1, L++; int t = R-L; for(int i=0; i<=t; i++) f[i] = i+L, num[i] = 1; for(int i=0; i<cnt&&p[i]*p[i]<=R; i++){ LL tmp = L; if(L % p[i]) tmp = (L/p[i]+1)*p[i]; for(LL j=tmp; j<=R; j+=p[i]){ LL cnt = 0; while(f[j-L]%p[i] == 0){ cnt++; f[j-L] /= p[i]; } num[j-L] = num[j-L]*(cnt*K+1)%MOD; } } for(int i=0; i<=t; i++){ if(f[i] == 1) ans = (ans + num[i]) % MOD; else ans = (ans + num[i]*(K + 1)) % MOD; } printf("%lld\n", ans); } return 0;}
阅读全文
0 0
- HDU 6069 Counting Divisors(素数筛法+枚举+技巧)——2017 Multi-University Training Contest
- HDU 6069 Counting Divisors(素数筛法+枚举+技巧)——2017 Multi-University Training Contest
- hdu 6069 Counting Divisors(约数个数)(2017 Multi-University Training Contest
- 2017 Multi-University Training Contest 4 && HDOJ 6069 Counting Divisors 【区间筛法】
- HDU 6069 Counting Divisors (2017 Multi-Univ Training Contest 4)
- HDU 6038 Function(找规律)——2017 Multi-University Training Contest
- HDU 6055 Regular polygon(计算几何+思维)——2017 Multi-University Training Contest
- HDU 6053 TrickGCD(分块+容斥)——2017 Multi-University Training Contest
- HDU 6048 Puzzle(找规律)——2017 Multi-University Training Contest
- HDU 6127 Hard challenge(思维+计算几何)——2017 Multi-University Training Contest
- HDU 6128 Inverse of sum(数论)——2017 Multi-University Training Contest
- HDU 3068 2017 Multi-University Training Contest
- HDU 6034 & 2017 Multi-University Training Contest
- hdu 6034 2017 Multi-University Training Contest
- HDU 3065 2017 Multi-University Training Contest
- HDU 6047 2017 Multi-University Training Contest
- HDU 6052 2017 Multi-University Training Contest
- HDU 6058 2017 Multi-University Training Contest
- leetcode 62. Unique Paths
- spring boot gradle 构建添加外部 jar
- 15.3—细节实现题—Insert Interval
- fastDFS集群理解+搭建笔记
- 功能模块的验收测试
- HDU 6069 Counting Divisors(素数筛法+枚举+技巧)——2017 Multi-University Training Contest
- 15.4—细节实现题—Merge Intervals
- C++可变参数函数
- G
- 如果项目失败我们能收获什么?
- 15.5—细节实现题—Minimum Window Substring
- centos6.5安装 apache
- iis 403.17
- 15.6—细节实现题—Multiply Strings