Hdu6069 Counting Divisors(2017多校第4场)
2017-08-03 23:00
253 查看
Counting Divisors
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 1105 Accepted Submission(s): 393
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, given l,r and k,
your task is to calculate the following thing :
(∑i=lrd(ik))mod998244353
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 are 3 integers l,r,k(1≤l≤r≤1012,r−l≤106,1≤k≤107).
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
Source
2017 Multi-University Training Contest - Team 4
Recommend
liuyiding
—————————————————————————————————
题目的意思是求一个区间的每个数的因子数之和
思路:先去打一个1到1e6的素数表,然后去枚举每个素数在区间内的倍数,可以跳着枚举,计算出每个数对应的因子个数,对于每个数的因子个数就等于枚举的因子个数*k+1累乘起来,注意剩下的大素数的判断
比赛是也是素数打表枚举的 ,鬼知道怎么想的去枚举区间的每个数去求因子,妥妥TLE,也有过正解的想法,想过没想太透彻,感觉这种题值得好好反思警戒自己
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <map> #include <set> #include <stack> #include <queue> #include <vector> #include <bitset> #include <functional> using namespace std; #define LL long long const int INF = 0x3f3f3f3f; const LL mod = 998244353; bool vis[1000009]; LL prime[1000009], sum[1000009], a[1000009]; LL l, r, k; int cnt; void init() { memset(vis, true, sizeof vis); vis[0] = vis[1] = false; cnt = 0; for (int i = 2; i < 1000009; i++) { if (!vis[i]) continue; prime[cnt++] = i; for (int j = i * 2; j < 1000009; j += i) vis[j] = false; } } int main() { init(); int t; scanf("%d", &t); while (t--) { scanf("%lld%lld%lld", &l, &r, &k); for (int i = 0; i <= r - l; i++) sum[i] = 1, a[i] = i + l; LL ans = 0; for (int i = 0; i < cnt; i++) { LL p = (l / prime[i] + (l%prime[i] ? 1 : 0))*prime[i]; for (LL j = p; j <= r; j += prime[i]) { int res = 0; while (a[j - l] % prime[i] == 0) res++, a[j - l] /= prime[i]; sum[j - l] = sum[j - l] * ((1LL * res*k + 1) % mod) % mod; } } for (int i = 0; i <= r - l; i++) { if (a[i] != 1) sum[i] = sum[i] * (k + 1) % mod; ans = (ans + sum[i]) % mod; } printf("%lld\n", ans); } return 0; }
相关文章推荐
- Hdu6075 Questionnaire(2017多校第4场)
- 2017多校第4场 HDU 6073 Matching In Multiplication 拓扑排序,思维,DFS
- hdu6069 区间筛 2017多校第四场1003
- 【区间筛】2017多校训练四 HDU6069 Counting Divisors
- 由HDU6069 Counting Divisors学习埃式筛法+区间筛法(2017多校第四场1003)
- Hdu6068 Classic Quotation(2017多校第4场)
- 2017多校第4场 HDU 6071 Lazy Running 同余最短路
- 2017多校第4场 HDU 6078 Wavel Sequence DP
- 2017多校第4场 HDU 6070 Dirt Ratio 分数规划,线段树
- 2017多校第4场 HDU 6078 Wavel Sequence DP,计数
- 2017多校第4场 HDU 6069 Counting Divisors 素筛,暴力,优化
- 2017多校第4场 HDU 6074 Phone Call 并查集,LCA
- 2013暑假新生赛第4场 Problem E: 机器人
- 多校第4场1012
- JZOJ3870. 【NOIP2014八校联考第4场第1试10.19】单词检索(search)
- 【JZOJ3873】【NOIP2014八校联考第4场第2试10.20】乐曲创作(music)
- HDU6033-2017多校第一场-Add More Zero
- 2017多校第二场 HDU 6053 TrickGCD 容斥,素数,思维
- 2017多校训练第二场 hdu6047 Maximum Sequence(贪心)
- 2017多校联合第一场 1003题 hdu 6035 Colorful Tree 部分对整体的贡献 + 补集思想 + 树分块