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

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

约数个数定理就是:

对于一个大于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. flex(1)

    flex使用的actionscript语言遵守ECMA-262标准,这与javascript语言是一致的,由此可见二者语法的相似.

  2. Codevs 1961 躲避大龙

    1961 躲避大龙  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 你早上起来,慢悠悠地来到学校门口, ...

  3. 洛谷P4151 [WC2011]最大XOR和路径(线性基)

    传送门 不知道线性基是什么东西的可以看看蒟蒻的总结 首先看到异或就想到线性基 我们考虑有一条路径,那么从这条路径走到图中的任意一个环再走回这条路径上,对答案的贡献是这个环的异或和,走到这个环上的路径对 ...

  4. [Xcode 实际操作]九、实用进阶-(22)Storyboard故事板的常用布局结构

    目录:[Swift]Xcode实际操作 本文将演示如在使用故事板搭建项目时,常用的一种故事板布局结构. 在项目导航区,打开故事板文件[Main.storyboard] 当前故事板中只有一个视图控制器控 ...

  5. Unrecogized font family ‘Ionicons’ 在ios上报错,android正常

    解决方法: react-native link react-native-vector-icons 很多模块都需要link一下

  6. SpringBlade 2.0-RC3 发布,全新的微服务开发平台

    经过了十天的艰苦奋斗,SpringBlade 2.0-RC3发布了,此版本增加了很多有用的功能,距离正式版本更近一步! SpringBlade简介: SpringBlade 2.0 是一个基于 Spr ...

  7. day01 包 权限修饰符 static final

  8. iOS 更改状态栏、导航栏颜色的几种方法

    ios上状态栏 就是指的最上面的20像素高的部分状态栏分前后两部分,要分清这两个概念,后面会用到: 前景部分:就是指的显示电池.时间等部分:背景部分:就是显示黑色或者图片的背景部分: (一)设置sta ...

  9. Jmeter-提取Json数据进行关联

      1:Json后置处理器提取结果作为下一个sampler的传入参数 1.1:[线程组]->[简单控制器]->[HTTP sampler]->[Beanshell后置取样器]-> ...

  10. HDU6301(2018多校第一场)

    Bryce1010模板 http://acm.hdu.edu.cn/showproblem.php?pid=6301 队友AC的,没怎么看 #include<iostream> #incl ...