HDU 6069 Counting Divisors (素数+筛法)
题意:给定 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 (素数+筛法)的更多相关文章
- HDU 6069 Counting Divisors(区间素数筛法)
题意:...就题面一句话 思路:比赛一看公式,就想到要用到约数个数定理 约数个数定理就是: 对于一个大于1正整数n可以分解质因数: 则n的正约数的个数就是 对于n^k其实就是每个因子的个数乘了一个K ...
- hdu 6069 Counting Divisors 筛法
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
- HDU 6069 Counting Divisors
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
- hdu 6069 Counting Divisors(求因子的个数)
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
- 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 ...
- 2017ACM暑期多校联合训练 - Team 4 1003 HDU 6069 Counting Divisors (区间素数筛选+因子数)
题目链接 Problem Description In mathematics, the function d(n) denotes the number of divisors of positiv ...
- HDU 6069 Counting Divisors(唯一分解定理+因子数)
http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 思路: 根据唯一分解定理,$n={a_{1}}^{p1}*{a2_{}}^{p2}...*{a_{ ...
- hdu 6069 Counting divisors 公式+区间筛
比赛的时候把公式扣出来了,,但是没有想到用筛法算公因子,,默默学习一下.. 题解:设n=p1^(c1)p2^{c2}...pm^{cm},n=p1^c1*p2^c2...p ...
- 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 ...
随机推荐
- Nmon、nmon analyse安装及使用
性能监控算是性能测试中的一部分,测试人员需要去分析各类系统指标,CPU.网络.内存.磁盘I/O等等.嗯.通常linux系统下有诸如top.netstat.iostat等命令进行查看:而有时需要看某数据 ...
- 安装nagios检测hadoop
Nagios是常用的系统监控工具,提供了很多基本服务的监控脚本,如HTTP,MYSQL等,同时具有不错的可扩展性,自己可定制针对特定参数的监控脚本以及报警的方式. 我现在有三台机器:192.168.0 ...
- linux文件权限,用户和组
文件权限 默认权限分配 umask umask是通过八进制的数值来定义用户创建文件或目录的默认权限的 安全权限的临界点是,文件默认权限是644,目录默认权限是755 [root@Poppy joker ...
- List、Set、Map下各类型的对比
1.List和Set: List: 元素有放入顺序,元素可重复,查找效率高,插入删除效率低: Set: 元素无放入顺序,元素不可重复,(元素虽然无顺序,但元素在Set中的位置是由该元素的HashCod ...
- Mysql踩过的坑
数据表示例 1.NOT IN 结果集为空 ①SELECT class_no FROM t_student; 结果为: ②SELECT * FROM t_student where class_no n ...
- svg_png
#!/usr/bin/env python#-*- encoding=UTF-8 -*-from __future__ import print_functionimport sysimport ra ...
- new及placememt new 异同点
new与定位new 区别如下: 简单概括: new 分配的内存地址空间来自于heap堆,用完需使用delete 释放内存 定位new 使用的不是heap堆内存,因此不需要使用delete 释放 定位n ...
- 修改android Studio SDK 路径产生的问题(模拟器不能启动了)
原因:将 c:\user\admin\appdata\android\sdk 修改为 F:\AndroidProgram\Sdk 原来的虚拟机不能用了,要新建虚拟机才可以.
- oracle常用函数总结(二)
之前也有写过“oracle常用函数总结(一)”,为了尽量找全常见oracle函数,笔者特意查找了相关资料来作为参考,下边给大家罗列出来,部分和之前有重复的,希望能帮到大家! 列举了31个函数和1个分组 ...
- 深入理解Java线程池
我们使用线程的时候就去创建一个线程,这样实现起来非常简便,但是就会有一个问题: 如果并发的线程数量很多,并且每个线程都是执行一个时间很短的任务就结束了,这样频繁创建线程就会大大降低系统的效率,因为频繁 ...