题意:给定 l,r,k,让你求,其中 l <= r <= 1e12, r-l <= 1e6, k <= 1e7。

析:首先这个题肯定不能暴力,但是给定的区间较小,可以考虑筛选,n = p1^c1*p2^c2*....*pn^cn,那么 d(n) = (c1+1) * (c2+1) * ...*(cn+1)。

d(n^k) =  (kc1+1) * (kc2+1) * ...*(kcn+1),这样的话,我们只要求出每个数的素因子的个数就好,直接算还是不行,只能先把1-sqrt(n)之间的素数先算出来,这个是可以实现的,然后再考虑枚举素数,然后计算在 l - r 这个区间内的数进行筛选,也就是说从第一个能整除prime[i]的数开始,假设是x,先把prime[i]除尽,然后再把 x 加上prime[i],再除尽,依次。。。这样的话,复杂度会小很多。注意mod的不是1e9+7

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e6 + 10;
const LL mod = 998244353;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r > 0 && r <= n && c > 0 && c <= m;
}
vector<int> prime;
bool vis[maxn]; void init(){
for(int i = 2; i < maxn; ++i) if(!vis[i]){
prime.push_back(i);
if(i > 1000) continue;
for(int j = i*i; j < maxn; j += i) vis[j] = 1;
}
} LL sum[maxn], a[maxn]; int main(){
init();
int T; cin >> T;
while(T--){
LL k, n, m;
scanf("%I64d %I64d %I64d", &m, &n, &k);
for(int i = 0; i <= n-m; ++i){
sum[i] = 1LL;
a[i] = i + m;
} for(int i = 0; i < prime.size(); ++i){
LL st = (LL)(m/prime[i] + (m%prime[i] != 0)) * prime[i];
for(LL j = st; j <= n; j += prime[i]){
int res = 0;
while(a[j-m] % prime[i] == 0){
++res; a[j-m] /= prime[i];
}
sum[j-m] = ((k * res % mod + 1LL) * sum[j-m]) % mod;
}
} LL ans = 0;
for(int i = 0; i <= n - m; ++i){
if(a[i] > 1LL) sum[i] = sum[i] * (k + 1) % mod;
ans = (ans + sum[i]) % mod;
}
printf("%I64d\n", ans);
}
return 0;
}

  

HDU 6069 Counting Divisors (素数+筛法)的更多相关文章

  1. HDU 6069 Counting Divisors(区间素数筛法)

    题意:...就题面一句话 思路:比赛一看公式,就想到要用到约数个数定理 约数个数定理就是: 对于一个大于1正整数n可以分解质因数: 则n的正约数的个数就是 对于n^k其实就是每个因子的个数乘了一个K ...

  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

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

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

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

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

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

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

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

  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. 学生党成功拿到阿里技术offer:面Java开发,却是C++考官,几个意思?

    摘要: 这是我为大家分享的如何拿到阿里技术offer系列文章中的第一篇,今天分享的文章的作者是一位在2015年阿里的校招中成功得到offer的美女学姐,从学姐的这篇文章中我们能学到很多在阿里面试的宝贵 ...

  2. 手机页面开发的meta

    <meta name="viewport" content="width=device-width, initial-scale=1"> 手机环境. ...

  3. JavaScript笔记——使用AJax

    在使用过JQuery之后,再来看JavaScript的Ajax实现就会觉得很麻烦,不过,最近使用到了,就记录一下吧 在JavaScript中Ajax的实现可以分为四步: 第一步 得到XMLHttpRe ...

  4. dt转实体

    public class DtConvertToList<T> where T : new() { /// <summary> /// 实体转换辅助类 /// </sum ...

  5. TCP报文大小

    链路层(二层)MTU最大传输单元:1500KByte.每个以太网帧64bytes-1518bytes,减去帧头(DMAC目的MAC地址48bit=6Bytes+SMAC源MAC地址48bit=6Byt ...

  6. 解决git报ssh variant 'simple' does not support setting port

    解决办法 在git bash中输入命令 git config --global ssh.variant ssh

  7. nginx-rtmp-module--------------WIKI

    https://github.com/arut/nginx-rtmp-module/wiki/Directives#idle_streams ============================= ...

  8. Sublime Text:初学者不知道的那些事

    来源:Duchessjojo@译言 我是Sublime Text代码编辑器的忠实粉丝.我和诸多Mac程序员一样,最初使用的是Textmate代码编辑器.在Sublime Text 2发行后,我才开始转 ...

  9. Python修饰器讲解

    转自:http://www.cnblogs.com/rollenholt/archive/2012/05/02/2479833.html 文章先由stackoverflow上面的一个问题引起吧,如果使 ...

  10. C#中的goto

    int i = 9;if (i % 2 == 0) goto Found;else goto NoFound; NoFound:            Console.WriteLine(i.ToSt ...