Counting Divisors

Problem Description
In mathematics, the function d(n) denotes the number of divisors of positive integer n.

For example, d(12)=6 because 1,2,3,4,6,12 are all 12's divisors.

In this problem, given l,r and k, your task is to calculate the following thing :

(∑i=lrd(ik))mod998244353

 
Input
The first line of the input contains an integer T(1≤T≤15), denoting the number of test cases.

In each test case, there are 3 integers l,r,k(1≤l≤r≤1012,r−l≤106,1≤k≤107).

 
Output
For each test case, print a single line containing an integer, denoting the answer.
 
Sample Input
3
1 5 1
1 10 2
1 100 3
 
Sample Output
10
48
2302
 
这题实质上就是分解质因数,不过不能对每个数都分解一次,这样肯定超时。
要用线性的方法求质因数。
设i可以分解为a1,a2,a3,a4……am,则总数加上(a1*k+1)*(a2*k+1)*……(am*k+1)
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#define ll long long
using namespace std;
#define ll long long
const int mod=;
const int maxn=;
int prime[maxn];
bool vis[maxn];
int top;
ll a[maxn];
ll b[maxn]; void pri()
{
top=;
memset(vis,,sizeof vis);
vis[]=;
for(int i=; i<maxn; i++)
{
if(!vis[i])
prime[top++]=i;
for(int j=; j<top&&i*prime[j]<maxn; j++)
{
vis[i*prime[j]]=;
if(i%prime[j]==)
break;
}
}
} void fun(ll l,ll r,ll k)
{
for(ll i=l; i<=r; i++)
b[i-l]=i;
for(ll i=l; i<=r; i++)
a[i-l]=;
for(ll i=; i<top&&prime[i]<=sqrt(r); i++)
{
ll x=l/prime[i];
if(x*prime[i]<l)
x++;
for(ll j=x; j*prime[i]<=r; j++)
{
ll s=;
while(b[prime[i]*j-l]%prime[i]==)
{
s++;
b[prime[i]*j-l]/=prime[i];
}
a[prime[i]*j-l]=a[prime[i]*j-l]*(s*k+)%mod;
}
}
for(ll i=l; i<=r; i++)
if(b[i-l]>)
a[i-l]=a[i-l]*(k+)%mod;
} int main()
{
pri();
int T;
scanf("%d",&T);
while(T--)
{
ll l,r;
ll k;
scanf("%lld%lld%lld",&l,&r,&k);
ll sum=;
fun(l,r,k);
for(ll i=l; i<=r; i++)
sum=(sum+a[i-l])%mod;
printf("%lld\n",sum);
}
return ;
}

HDU 6069的更多相关文章

  1. HDU 6069 Counting Divisors(唯一分解定理+因子数)

    http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 思路: 根据唯一分解定理,$n={a_{1}}^{p1}*{a2_{}}^{p2}...*{a_{ ...

  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. 2017ACM暑期多校联合训练 - Team 4 1003 HDU 6069 Counting Divisors (区间素数筛选+因子数)

    题目链接 Problem Description In mathematics, the function d(n) denotes the number of divisors of positiv ...

  6. HDU 6069 Counting Divisors (素数+筛法)

    题意:给定 l,r,k,让你求,其中 l <= r <= 1e12, r-l <= 1e6, k <= 1e7. 析:首先这个题肯定不能暴力,但是给定的区间较小,可以考虑筛选, ...

  7. Counting Divisors HDU - 6069

    设n=p_1^{c_1}p_2^{c_2}...p_m^{c_m}n=p​1​c​1​​​​p​2​c​2​​​​...p​m​c​m​​​​,则d(n^k)=(kc_1+1)(kc_2+1)...( ...

  8. [hdu 6069]素数筛+区间质因数分解

    给[L,R]区间的每一个数都质因数分解的复杂度可以达到(R-L)logR,真的涨姿势…… 另外,质因数分解有很重要的一点,就是只需要打sqrt(R)以内的素数表就够了……因为超过sqrt(R)的至多只 ...

  9. HDU 6069 Counting Divisors(区间素数筛法)

    题意:...就题面一句话 思路:比赛一看公式,就想到要用到约数个数定理 约数个数定理就是: 对于一个大于1正整数n可以分解质因数: 则n的正约数的个数就是 对于n^k其实就是每个因子的个数乘了一个K ...

随机推荐

  1. eclipse下建立 android 项目,相关文件夹介绍

    今天开始进入ANDROID开发,之前一直做些JAVA的WEBSERVICE之类的文件,第一次从头开始整理ANDROID项目,我会把最近遇到的问题做一一梳理. 现在来说一下建立ANDROID项目后产生的 ...

  2. Laravel踩坑笔记——illuminate/html被抛弃

    起因 在使用如下代码的时候发生报错 {!! Form::open() !!} 错误信息 [Symfony\Component\Debug\Exception\FatalErrorException] ...

  3. cURL模拟网页登陆

    <?php /** * Created by PhpStorm. * User: Administrator * Date: 2016/7/13 * Time: 23:15 */ $data=' ...

  4. 【LeetCode】144. Binary Tree Preorder Traversal

    题目: Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binar ...

  5. 高级Java程序员的技术进阶之路

      据不完全统计,截至目前(2017.07)为止,中国Java程序员的数量已经超过了100万.而且,随着IT培训业的持续发展和大量的应届毕业生进入社会,Java程序员面临的竞争压力越来越大.那么,作为 ...

  6. ionicangular 成长日记

    //首先配置文件ionic.bundle.min.jsionic.min.css" //创建一个angular控制器,控制器给body/html都可以angular.module('myap ...

  7. laravel5.4+vue+element-ui配置及简单使用

    前言:网上能找到的关于这个方面的教程实在是太少啦,所以踩了好多坑,特意来分享一下,原创哦.想要打包带走的小伙伴还请注明出处

  8. window.onload的使用心得

    如果我问你window.onload是什么意思,恐怕你会回答我:"这不是页面加载完就执行吗".  但是答案是不一定,得看你怎么用.看一下例子吧 例1:  代码如下:   <! ...

  9. 免费MD5解密网站,轻松破解md5密码,mysql5/mysql323,ntlm,salt密码

    md5解密网站:http://cmd5.la 网站语言:php 免费指数:★★★        (8位内小写数字字母免费,11位内数字免费) 解密范围:★★★★☆ (覆盖了1-12位很多常用密码和特殊 ...

  10. jQuery手风琴的制作!!

    jQuery手风琴的制作 首先我们先来做一个简单的jQuery的效果图 效果图 如下: css代码 如下: <style type="text/css" media=&quo ...