题意:给定 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. Java 中的instanceof 运算符

    Java 中的instanceof 运算符是用来在运行时指出对象是否是特定类的一个实例.instanceof通过返回一个布尔值来指出,这个对象是否是这个特定类或者是它的子类的一个实例. 用法:resu ...

  2. hadoop map端的超时参数

    目前集群上某台机器卡住导致出现大量的Map端任务FAIL,当定位到具体的机器上时,无法ssh或进去后terminal中无响应,退出的相关信息如下: [hadoop@xxx ~]$ Received d ...

  3. 多个else if语句

    public class demo { public static void main(String[] args) { boolean examIsDone = true; int score = ...

  4. 【汇总】C#数据类型及转换

    13.C# 16进制与字符串.字节数组之间的转换 https://www.cnblogs.com/seventeen/archive/2009/10/29/1591936.html C# 对象.文件与 ...

  5. 关于c3p0 ResourcePoolException: Attempted to use a closed or broken resource pool

    转自:https://blog.csdn.net/u011404265/article/details/52848603 springmvc-servlet.xml加入 <property na ...

  6. C++STL:流迭代器

    流迭代器是一种迭代器适配器.istream_iterator用于读取输入流,ostream_iterator用于写输出流.这些迭代器将它们所对应的流视为特定类型的元素序列.使用流迭代器时,可以用泛型算 ...

  7. MyBatis 学习记录4 MyBatis的一级缓存

    主题 分享记录一下MyBatis的一级缓存相关的学习. Demo public static void firstLevelCache() { init("mybatis-config.xm ...

  8. 产品负责人(Product Owner)的主要职责和技能

    角色介绍 产品负责人以下简称PO,他是有授权的产品领导力核心,组成Scrum团队三个角色之一. PO担任的是产品经理的角色. PO的主要职责 1.对产品的ROI负责. ROI = profitabil ...

  9. NHibernate注意事项

    1.检查映射文件是否正确 2.检查配置文件的“嵌入的资源”选项 3.检查Configuration是否加载了程序集

  10. 关于setTimeout()你所不知道的地方

    前言:看了这篇文章,1.注意setTimeout引用的是全部变量还是局部变量了,当直接调用外部函数方法时,实际上函数内部的变量已经变成全 局.2.提醒我防止出错的,用匿名函数不容易出错.3.setTi ...