2017多校四 1003题 hdu 6069 Counting Divisors 分解质因数
来源:互联网 发布:淘宝女装修图教程 编辑:程序博客网 时间:2024/06/05 17:28
题目链接
参考:http://blog.csdn.net/protecteyesight/article/details/76685920 ——protecteyesight
题意:
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
思路:
设n=p1c1p2c2...pmcm,则d(nk)=(kc1+1)(kc2+1)...(kcm+1)
这一点是显然的,关键问题就在于怎么高效的分解质因数。
比赛时不会做然后干脆就放弃了...后半场就去补以前的题了心态十分消极
(觉得现在的一个很大问题就是想想觉得会T就不去写了...其实有的时候还真不一定,当然这道题蛮做的话肯定会T
但问题又不仅限于不去写了,而是好像就直接放弃了再去思考...具体的我也说不清...sigh)
言归正传。
高效的做法是:并没有对每个数去依次分解质因数,而是依次去看每个质数能成为哪些数的因数。同样,也可以说是看 贡献 的想法。
质数的话只需要提前处理出 1e6 范围内的即可,因为在 1e6 到 1e12 范围内的数,如果没有 1e6 范围内的质数因子,其本身就必然是一个质数。
所以,只需要在考虑完所有的质数因子之后再去判断每个数最后是不是 1,如果不是,说明该数有一个大于 1e6 的质数因子,再乘上 (k + 1) 即可。
具体处理的时候:
1. 将 [l, r] 的数挪到 [0, l - r] 的区间去存,以便之后除以 prime[ ]。
2. 直接算出 [l, r] 的区间内第一个被 prime[i] 整除的数的值,而不要一个个去枚举浪费时间。
Code:
#include <bits/stdc++.h>#define maxn 1000000#define mod 998244353typedef long long LL;bool vis[maxn + 10];int prime[maxn + 10], tot;LL a[maxn + 10], cnt, mul[maxn + 10];void pre() { for (int i = 2; i <= maxn; ++i) { if (!vis[i]) { prime[tot++] = i; } for (int j = 0; j < tot; ++j) { if (i * prime[j] > maxn) break; vis[i * prime[j]] = true; if (i % prime[j] == 0) break; } }}void work() { LL l, r, k; scanf("%lld%lld%lld", &l, &r, &k); for (LL i = l; i <= r; ++i) a[i - l] = i, mul[i - l] = 1; LL r0 = r; r -= l; for (int i = 0; i < tot; ++i) { if (prime[i] > r0) break; int j = ceil((double)l / prime[i]) * prime[i] - l; for (int jj = j; jj <= r; jj += prime[i]) { LL cnt = 0; while (a[jj] % prime[i] == 0) ++cnt, a[jj] /= prime[i]; mul[jj] = mul[jj] * (k * cnt % mod + 1) % mod; } } for (int i = 0; i <= r; ++i) if (a[i] > 1) mul[i] *= (k + 1), mul[i] %= mod; LL sum = 0; for (int i = 0; i <= r; ++i) sum += mul[i], sum %= mod; printf("%lld\n", sum);}int main() { pre(); int T; scanf("%d", &T); while (T--) work(); return 0;}
阅读全文
0 0
- 2017多校四 1003题 hdu 6069 Counting Divisors 分解质因数
- 2017杭电多校第四场1003 Counting Divisors (分解质因数) hdu 6069
- hdu6069 Counting Divisors 质因数分解 区间筛
- HDU 4432 Sum of 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
- HDU 6069 Counting Divisors
- hdu--6069--Counting Divisors
- HDU-6069 Counting Divisors
- HDU-6069 Counting Divisors
- 异步请求上传图片
- js严格模式
- 6种负载均衡算法
- XYNUOJ 第四次比赛 懒省事得小名
- L2-005. 集合相似度
- 2017多校四 1003题 hdu 6069 Counting Divisors 分解质因数
- 排序--2
- Rabbitmq
- C语言系统编程
- web前端知识体系
- 这个夏天有点热
- 消失的7
- 如何定义数组
- 进制转换