题意:。。。就题面一句话

思路:比赛一看公式,就想到要用到约数个数定理

约数个数定理就是:

对于一个大于1正整数n可以分解质因数

则n的正约数的个数就是

对于n^k其实就是每个因子的个数乘了一个K
然后现在就变成了求每个数的每个质因子有多少个,但是比赛的时候只想到sqrt(n)的分解方法,总复杂度爆炸,就一直没过去,然后赛后看官方题解感觉好妙啊!
通过类似素数筛法的方式,把L - R的质因子给分解,就可以在O(nlogn)的时间之内把所以的数给筛出来。
代码:
/** @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(区间素数筛法)的更多相关文章

  1. hdu 6069 Counting Divisors 筛法

    Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Oth ...

  2. HDU 6069 Counting Divisors

    Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Oth ...

  3. 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 ...

  4. hdu 6069 Counting Divisors(求因子的个数)

    Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Oth ...

  5. 2017ACM暑期多校联合训练 - Team 4 1003 HDU 6069 Counting Divisors (区间素数筛选+因子数)

    题目链接 Problem Description In mathematics, the function d(n) denotes the number of divisors of positiv ...

  6. HDU 6069 Counting Divisors (素数+筛法)

    题意:给定 l,r,k,让你求,其中 l <= r <= 1e12, r-l <= 1e6, k <= 1e7. 析:首先这个题肯定不能暴力,但是给定的区间较小,可以考虑筛选, ...

  7. hdu 6069 Counting divisors 公式+区间筛

    比赛的时候把公式扣出来了,,但是没有想到用筛法算公因子,,默默学习一下.. 题解:设n=p1^(c1)p2^{c2}...pm^{cm},n=p​1^​c​1*​​​​p​2​^c​2​​​​...p ...

  8. HDU 6069 Counting Divisors(唯一分解定理+因子数)

    http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 思路: 根据唯一分解定理,$n={a_{1}}^{p1}*{a2_{}}^{p2}...*{a_{ ...

  9. 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 ...

随机推荐

  1. c/c++面试45-50之字符串

    45 使用库函数将数字转换为字符串,下面是常用库函数 (1) itoa():将整型转换为字符串 (2)ltoa():将长整形转换为字符串 (3)gcvt():将浮点转换为字符串 46 不使用库函数将整 ...

  2. Flutter实战视频-移动电商-55.购物车_底部结算栏UI制作

    55.购物车_底部结算栏UI制作 主要做下面结算这一栏目 cart_bottom.dart页面 先设置下内边距 拆分成三个子元素 全选 因为有一个文本框和一个全选的text文本,所以这里也用了Row布 ...

  3. Laravel框架之Session操作

    //设置session里的值 public function session1(Request $request){ //1.HTTP request session(); /*$request-&g ...

  4. C和FORTRAN的快速傅里叶/余弦/正弦变换(Fast Fourier/Cosine/Sine Transform)开源库分享

    Takuya Ooura: General Purpose FFT Package, http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html. Free C & ...

  5. yzm10铺瓷砖 yzm10原创系列

    yzm10铺瓷砖 一天yzm10接到任务,要求用2×1大小的瓷砖,来铺2×4的地面,地面需要恰好被铺满.这对yzm10来说太容易了,于是他马上设计出了5种不同的铺法(旋转情况算不同种,如图示2.4). ...

  6. 快速打开和关闭SQL服务

    将下面文本复制到txt中,然后将文本文件另存为bat @echo off for /f "skip=3 tokens=4" %%i in ('sc query MSSQLSERVE ...

  7. ORM取数据很简单!是吗?

    简介 几乎任何系统都以某种方式与外部数据存储一起运行.大多数情况下,外部数据存储是一个关系数据库,并且在实现时通常将数据提取任务委托给某些 ORM. 尽管 ORM 包含很多 routine 代码,但是 ...

  8. Mol Cell Proteomics. |胡丹丹| 雷公藤红素通过SIRT1-FXR 信号通路保护胆汁淤积性肝损伤

    期刊:Mol Cell Proteomics 题目:Celastrol protects from cholestatic liver injury though modulation of SIRT ...

  9. iOS开发 - CocoaPods的常见使用方式

    1 CocoaPods 的安装 1.1 作用: 帮助管理和维护第三方框架,快速的搜索到第三方框架, 然后自动集成到工程里面来, 并编译成一个libPod.a的静态库给我们项目用 1.2 理解:  1. ...

  10. salt命令

    salt-key -L list在master上所有收到的公钥连接请求 -A accept所有pending的请求. -D 删除所有 在minion上启动服务后,几十秒后会在/etc/salt/pki ...