HDU 6069 Counting Divisors (素因子求贡献)
来源:互联网 发布:洗菜盆 知乎 编辑:程序博客网 时间:2024/05/29 15:21
数论 素数 素分解 贡献 HDU 2017多校赛
Description
给定
其中
Input
第一行给出用例组数
Output
对于每组测试用例,输出一个整数表示答案。
Sample Input
31 5 11 10 21 100 3
Sample Output
10482302
Solution
易知若
一个数n的素因子主要分布在
区间
时间复杂度为
Code
#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;typedef long long ll;const int INF = 0x3f3f3f3f;const ll mod = 998244353;const int N = 1e6 + 10;int is_prime[N], prime[N], tot;void get_prime(int n){ for (int i = 1; i <= n; i++) is_prime[i] = true; is_prime[0] = is_prime[1] = false; tot = 0; for (int i = 2; i <= n; i++) { if (is_prime[i]) prime[tot++] = i; for (int j = 0; j < tot && prime[j] * i <= n; j++) { is_prime[prime[j] * i] = false; if (i % prime[j] == 0) break; } }}ll a[N], d[N];int main(){ int T; scanf("%d", &T); get_prime(1e6); while (T--) { ll l, r, k; scanf("%lld%lld%lld", &l, &r, &k); for (ll i = l; i <= r; i++) a[i - l] = i, d[i - l] = 1;; for (int i = 0; i < tot; i++) { ll p = prime[i]; ll t = ceil((double)l / p) * p; for (ll j = t; j <= r; j += p) { int tot = 0; while (a[j - l] % p == 0) tot++, a[j - l] /= p; d[j - l] = d[j - l] * (tot * k % mod + 1) % mod; } } ll ans = 0; for (ll i = l; i <= r; i++) { if (a[i - l] != 1) d[i - l] = d[i - l] * (k + 1) % mod; ans = (ans + d[i - l]) % mod; } printf("%lld\n", ans); } return 0;}
Link
http://acm.hdu.edu.cn/showproblem.php?pid=6069
阅读全文
0 0
- 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
- hdu--6069--Counting Divisors
- HDU-6069 Counting Divisors
- HDU-6069 Counting Divisors
- HDU 6069 Counting Divisors
- 来自一个java小白的自白
- 在大学老师布置的一些题目,欢迎各位大佬指正(2)
- 多线程的2种实现方式
- 【设计模式】单例模式
- 二叉树
- HDU 6069 Counting Divisors (素因子求贡献)
- Struts2 官方教程:动作编程(Coding actions)
- 算法训练 K好数
- 组件化
- JS事件知识点总结
- 朴素贝叶斯算法详解
- 项目二——停车场
- 容斥原理(模板+例题)
- [USACO3.4.4]rockers