题意:给定 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. NGUI的UICamera

    参考 https://blog.csdn.net/kakashi8841/article/details/20548429   全文请查看:http://note.youdao.com/notesha ...

  2. Mysql无法创建外键的原因 !!!

    在MySQL中创建外键时,经常会遇到问题而失败,这是因为Mysql中还有很多细节需要我们去留意,我自己总结并查阅资料后列出了以下几种常见原因. 1.  两个字段的类型或者大小不严格匹配.例如,如果一个 ...

  3. Java测试用例简介

    最近需要向组内其他成员普及一下关于Java测试用例的相关知识,特在此进行一下简单的学习和总结. JUnit简介 JUnit是一个开源的Java单元测试框架,JUnit4对原有的JUnit框架进行了大幅 ...

  4. 在centOS5.9安装mysql

    网上的信息实在是太乱了,好多出了错的,我这个是自己亲自配置,其实就简简单单的几步:如果你的系统里有以前遗留的文件,用rm -rf文件名删除掉 1.安装MySQL客服端和服务器端             ...

  5. node中一个基本的HTTP客户端向本地的HTTP服务器发送数据

    上一篇讲到了node可以轻松的向其他请求数据. 这一篇就来讲讲向本地服务器的数据交互. HTTP服务器代码,s.js var http=require("http"); var s ...

  6. Nginx压力测试工具之WebBench

    Nginx压力测试工具之WebBench   在Apache中有自带的ab命令可以测试服务的压力,而nginx没有自带的命令,必须要采用第三方软件来测试,今天就简单介绍一下webbench对nginx ...

  7. OD 实验(八) - 对一个程序的逆向

    程序: 运行 弹出 NAG 窗口,提示要花 20 美元注册 然后会进入主窗口 提示剩余 5 天的使用时间 点击,菜单栏 -> Help -> About 显示未注册版本 逆向: 用 OD ...

  8. 微信登录失败,redirect_uri域名与后台配置不一致,错误代码10003

    微信登录失败,redirect_uri域名与后台配置不一致,错误代码10003 1 先检查网页的授权域名  不要带http:// 2 检查下自己的appid是否正确 我换了appid没上传,多花了时间 ...

  9. 【MATLAB】读取和写入文本文件

    在MATLAB中,来读取和写入文本文件是很简单的事.下面,就来简单介绍下.如果有其他问题,请留言. 一.读取文本文件 思路: 1.用fopen来打开一个文件句柄 2.用fgetl来获得文件中的一行,如 ...

  10. adb命令检测apk启动时间、内存、CPU使用情况、流量、电池电量等——常用的adb命令

    ADB:Android Debug Bridge,是Android SDK里一个可以直接操作安卓模拟器或真实设备的工具,颇为强大.   检测APP:   adb shell am start -W p ...