HDU 6069 Counting Divisors(区间素数筛法)
题意:。。。就题面一句话
思路:比赛一看公式,就想到要用到约数个数定理
约数个数定理就是:
对于一个大于1正整数n可以分解质因数:则n的正约数的个数就是
/** @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(区间素数筛法)的更多相关文章
- 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 ...
- hdu 6069 Counting Divisors(求因子的个数)
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 (素数+筛法)
题意:给定 l,r,k,让你求,其中 l <= r <= 1e12, r-l <= 1e6, k <= 1e7. 析:首先这个题肯定不能暴力,但是给定的区间较小,可以考虑筛选, ...
- hdu 6069 Counting divisors 公式+区间筛
比赛的时候把公式扣出来了,,但是没有想到用筛法算公因子,,默默学习一下.. 题解:设n=p1^(c1)p2^{c2}...pm^{cm},n=p1^c1*p2^c2...p ...
- HDU 6069 Counting Divisors(唯一分解定理+因子数)
http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 思路: 根据唯一分解定理,$n={a_{1}}^{p1}*{a2_{}}^{p2}...*{a_{ ...
- 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 ...
随机推荐
- Laravel中使用模型对数据进行操作
public function orm(){ //查询表的所有记录 //$user = Admin::all(); //dd($user); //查询某一条记录 //$user = Admin::fi ...
- UVa 11825 Hackers' Crackdown (状压DP)
题意:给定 n 个计算机的一个关系图,你可以停止每台计算机的一项服务,并且和该计算机相邻的计算机也会终止,问你最多能终止多少服务. 析:这个题意思就是说把 n 台计算机尽可能多的分成一些组,使得每组的 ...
- 洛谷 - P2283 - 多边形 - 半平面交
https://www.luogu.org/problemnew/show/P2283 需要注意max是求解顺序是从右到左,最好保证安全每次都清空就没问题了. #include<bits/std ...
- MVC 基本工具(Visual Studio 的单元测试、使用Moq)
3.Visual Studio 的单元测试 有很多.NET单元测试包,其中很多是开源和免费的.本文打算使用 Visual Studio 附带的内建单元测试支持,但其他一些.NET单元测试包也是可用的. ...
- QuantLib 金融计算——基本组件之 ExchangeRateManager 类
目录 QuantLib 金融计算--基本组件之 ExchangeRateManager 类 概述 Money 类中的汇率转换配置 ExchangeRateManager 函数 如果未做特别说明,文中的 ...
- TopJUI通过简单的代码实现复杂的批量提交功能
业务系统的批量提交是常用的操作功能,使用传统的EasyUI开发时需要写不少代码才能实现,该功能在TopJUI中是如何实现的呢?本篇我们将通过简单的代码,把批量操作的具体实现分享给大家参考. <a ...
- SpringMVC注解校验
spring注解式参数校验 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/jinzhencs/article/details/5168283 ...
- js监听键盘提交表单
<!DOCTYPE html> <html> <head> <title>登陆系统</title> <link href=" ...
- JAVA常用知识总结(十三)——数据库(三)
Mysql的主键选择(主键自增,UUID,snowflake)? 使用自增长做主键的优点:1.很小的数据存储空间2.性能最好3.容易记忆使用自增长做主键的缺点:1.如果存在大量的数据,可能会超出自增长 ...
- 利用串口的硬件buf收发数据
很多单片机的串口可以设置硬件接收和发送的buf,这样可以减少中断的次数和cpu的浪费,方法就是:发送时根据串口波特率(通讯格式N-8-1)和硬件buf缓冲的字节数计算定时器的间隔(小于1000*buf ...

