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

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

约数个数定理就是:

对于一个大于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. 洛谷1601 A+B Problem(高精) 解题报告

    洛谷1601 A+B Problem(高精) 本题地址:http://www.luogu.org/problem/show?pid=1601 题目背景 无 题目描述 高精度加法,x相当于a+b pro ...

  2. android通过获取摄像头照片,实时与点传输

    http://blog.csdn.net/csh159/article/details/7926654/ GetIP: [html] view plain copy print? package co ...

  3. performSegueWithIdentifier:sender里边的sender是啥意思

    performSegueWithIdentifier:sender里边的sender是啥意思啊?怎样用啊? [self performSegueWithIdentifier:@"pushSi ...

  4. Git - .gitignore文件的用法

    .gitignore文件的作用 .gitignore文件用来忽略被指定的文件或文件夹的改动,被记录在.gitignore文件里的文件或文件夹,是无法被git跟踪到的,换句话说,被忽略的文件是不会被放入 ...

  5. jmeter beanshell处理请求响应结果时Unicode编码转为中文

    在Test Plan下创建一个后置BeanShell PostProcessor,粘贴如下代码即可: String s=new String(prev.getResponseData()," ...

  6. 页面嵌套时js失效解决方法

    事件:iframe或easyui的dialog嵌套页面时,被嵌套的页面可能js因位置失效; 解决: //动态加载js(根据父级html位置计算) jQuery.getScript("scri ...

  7. BZOJ1415(期望dp)

    解法: 首先bfs预处理go数组:可可在j点时聪聪在点i是怎样贪心走的,这是为了之后O(1)获取转移线路. 然后dfs记忆化一下f[i][j],代表从i到j的期望,对于每层:将所有情况的期望值相加.边 ...

  8. ZJOI2017 day2 T2 线段树 想法题

    考完D2发现自己简直zz了...花式扔基本分 首先这道题有个显然的套路:树上一些点到一个定点的距离和=这些点深度和+点数*定点深度和-2*lca深度和 ——上一次见这个套路是LNOI2014,上次做的 ...

  9. 转 查看磁盘IO负载 - 看哪些进程在读写磁盘 以及oracle 异步I/O 和同步I/O

    https://www.cnblogs.com/cloudstorage/archive/2012/11/11/2764623.html #####sample 1: Oracle等待事件db fil ...

  10. HDU 3359 高斯消元模板题,

    http://acm.hdu.edu.cn/showproblem.php?pid=3359 题目的意思是,由矩阵A生成矩阵B的方法是: 以a[i][j]为中心的,哈曼顿距离不大于dis的数字的总和 ...