题意:给定 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. 20181122_C#中AOP初探_装饰器模式的AOP_Remoting实现AOP_Castle实现AOP

    一.   什么是AOP: a)         AOP是面向切面编程; 就像oop一样, 它也是一种编程思想; i.    Oop思想→一切皆对象, 对象交互组成功能, 功能叠加组成模块, 模块叠加组 ...

  2. python学习 (三十五) logging

    1  demo import logging # log level: # DEBUG # INFO # Warning # Error # CRITICAL logging.basicConfig( ...

  3. 利用html5制作一个时钟动画

    <canvas id="clock" width="500" height="500" style="background- ...

  4. WP8 MVVM设计模式

    类似了Android里边的MVC模式, Windows Phone 有自己的Model-View-ViewModel模式,这种模式的作用就是为了Data和UI分离开来. 如果你英文较好的话,你可以不再 ...

  5. MySQL--产品的起源和状态

    MySQL这个名字,起源不是很明确.一个比较有影响的说法是,基本指南和大量的库和工具带有前缀“my”已经有10年以上,而且不管怎样,MySQL AB创始人之一的Monty Widenius的女儿也叫M ...

  6. PHP程序连接多个redis实例做缓存

    1.redis配置: $CONFIG_REDIS = array(     array('host' => '192.168.19.29', 'port' => '6379', 'dbIn ...

  7. PHP对全局变量_GET、_POST中特殊字符的过滤

     $sVariablesOrder = ini_get( 'variables_order' );      $request = array();      //过滤不安全数据   for ( $i ...

  8. django之admin站点

    Admin站点 通过使用startproject创建的项目模版中,默认Admin被启用 1.创建管理员的用户名和密码 python manage.py createsuperuser 然后按提示填写用 ...

  9. leetcode36

    public class Solution { public bool IsValidSudoku(char[,] board) { ; i < ; i++) { var dic = new D ...

  10. script放置最佳位置(转载)

    html文件是自上而下的执行方式,但引入的css和javascript的顺序有所不同,css引入执行加载时, 程序仍然往下执行,而执行到<script>脚本是则中断线程,待该script脚 ...