HDU 6069 Counting Divisors(区间素数筛法)
题意:。。。就题面一句话
思路:比赛一看公式,就想到要用到约数个数定理
约数个数定理就是:
对于一个大于1正整数n可以分解质因数:则n的正约数的个数就是
/** @xigua */
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <cstring>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <climits>
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef double db;
const int maxn = 1e6 + 5;
const int mod = 998244353;
const int INF = 1e8 + 5;
const ll inf = 1e15 + 5;
const db eps = 1e-6;
bool is[maxn];
ll pri[maxn]; int cnt; void init() {
for (int i = 2; i < maxn; i++) {
if (!is[i]) {
pri[++cnt] = i; //素数筛
for (int j = i + i; j < maxn; j += i)
is[j] = 1;
}
}
} ll fac[maxn], p[maxn]; void solve() {
ll l, r, k; cin >> l >> r >> k;
ll res = 0;
//通过1 到 (r - l + 1)的数组来表示 l 到 r
//fac代表当前数的因子个数,p代表当前数被分解之后的值
for (ll i = l; i <= r; i++)
fac[i-l+1] = 1, p[i-l+1] = i;
for (int i = 1; i <= cnt; i++) {
ll be;
if (l % pri[i] == 0) be = l;
else {
be = l + (pri[i] - l % pri[i]); //找到筛法的起点,因为有些不是从l开始的
}
for (ll j = be; j <= r; j += pri[i]) { //枚举be到r
//每次增加pri[i]就可以保证这个数肯定是pri[i]的倍数
ll tmp = 0;
while (p[j-l+1] % pri[i] == 0) { //看当前质因数的个数
tmp++;
p[j-l+1] /= pri[i];
}
fac[j-l+1] = fac[j-l+1] * (k * tmp % mod + 1) % mod;
}
}
for (ll i = l; i <= r; i++) {
//素数
if (p[i-l+1] != 1) fac[i-l+1] = fac[i-l+1] * (k + 1) % mod;
res = (res + fac[i-l+1]) % mod;
}
cout << res << endl;
} int main() {
int t = 1, cas = 1;
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
init();
scanf("%d", &t);
while(t--) {
// printf("Case %d: ", cas++);
solve();
}
return 0;
}
HDU 6069 Counting Divisors(区间素数筛法)的更多相关文章
- hdu 6069 Counting Divisors 筛法
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
- HDU 6069 Counting Divisors
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
- HDU 6069 Counting Divisors —— 2017 Multi-University Training 4
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
- hdu 6069 Counting Divisors(求因子的个数)
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
- 2017ACM暑期多校联合训练 - Team 4 1003 HDU 6069 Counting Divisors (区间素数筛选+因子数)
题目链接 Problem Description In mathematics, the function d(n) denotes the number of divisors of positiv ...
- HDU 6069 Counting Divisors (素数+筛法)
题意:给定 l,r,k,让你求,其中 l <= r <= 1e12, r-l <= 1e6, k <= 1e7. 析:首先这个题肯定不能暴力,但是给定的区间较小,可以考虑筛选, ...
- hdu 6069 Counting divisors 公式+区间筛
比赛的时候把公式扣出来了,,但是没有想到用筛法算公因子,,默默学习一下.. 题解:设n=p1^(c1)p2^{c2}...pm^{cm},n=p1^c1*p2^c2...p ...
- HDU 6069 Counting Divisors(唯一分解定理+因子数)
http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 思路: 根据唯一分解定理,$n={a_{1}}^{p1}*{a2_{}}^{p2}...*{a_{ ...
- HDU 6069 Counting Divisors(2017 Multi-University Training Contest - Team 4 )
Output For each test case, print a single line containing an integer, denoting the answer. Sample ...
随机推荐
- 二Java的常量与变量-1-1标识符
类的名字就是标识符 起类名也是不能带空格的
- UVaLive 6854 City (暴力)
题意:给定一个 n*m 的矩阵,表示有多少条道路与它相连,其中有一个-1,表示未知,道路只能横着和竖着,求-1处的值. 析:根据题意可知,一个点,与其他周围的四个点都可能相连的,也就是说肯定有共用道路 ...
- CentOS Linux 7 提示 lsof: 未找到命令
我们常使用 lsof -i:端口号 命令来查看某端口是否开放,如使用下面的命令,查看8080端口: lsof -i: 结果: 提示:lsof:未找到命令 解决办法 使用yum来安装lsof,命令如下: ...
- 商务系统的构造思路(无源码!)+如何用jsp实现点击单选框内容显示在另一个jsp页面
敲码经验总结: 之前犯了一个错误就是,没有从底层开始学起,有啥问题,就直接博客园找源码,去CSDN找源代码,看到代码就复制粘贴,结果从新梳理知识点的时候,貌似除了复制粘贴,印象深刻的知识啥也没学到. ...
- 利用Web服务生成产品编号 执行添加操作
为什么我想要执行添加操作,却添加不成功,系统提示我comm.ExecuteNonQuery有错误 已找到原因 在 string strsql = "insert into tb_goods( ...
- html Css PC 移动端 公用部分样式代码整理
css常用公用部分样式代码整理: body, html, div, blockquote, img, label, p, h1, h2, h3, h4, h5, h6, pre, ul, ol, li ...
- Day2课后作业:三级菜单简单版
menu = { '北京':{ '海淀':{ '五道口':{ 'soho':{}, '网易':{}, '谷歌':{} }, '中关村':{ '爱奇艺':{}, '汽车之家':{}, 'youku':{ ...
- 【bzoj1123】BLO
1123: [POI2008]BLO Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2222 Solved: 1090[Submit][Status ...
- CentOS7.2 安装iptables
1 先检查是否安装了iptables: service iptables status iptables -L ls /etc/sysconfig/ 综上:命令报错,且 iptables不存在,那 ...
- 页面在Native端滚动时模拟原生的弹性滚动效果
width: 100%;overflow: scroll;overflow-y: hidden;-webkit-overflow-scrolling: touch; ---- 对应的滚动内容内添加 ...