地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6069

题目:

Counting Divisors

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1235    Accepted Submission(s): 433

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
 
Source
 

思路:

  首先需要知道:一个数可以用唯一分解定理表示成:n=p1^a1*p2^2......*pn^an

         质约数个数为(a1+1)*(a2+1)*....*(an+1)

  那么n^k的质约数个数为(a1*k+1)*(a2*k+1)*.....*(an*k+1)

  所以这题的关键是求l,r区间每个数的质约数有那些,且次数是多少。

  考虑到:l,r最大为1e12,所以枚举1-1e6内的所有素数后即可知道l,r中每个数的质约数有哪些,同时可以知道次数是多少

  但是直接在1-1e6的素数表内查找l,r中的某个数的素约数的时间复杂度是O(1e6),显然不可行。

  所以可以通过线性筛的思想来求:对于1-1e6的素数,考虑他会在l,r内筛掉哪些数即可。

  因为1e12每个数最多有20左右的质约数,所以时间复杂度是O((r-l)*20)+O(1e5)(质数表大小)

  

 #include <bits/stdc++.h>

 using namespace std;

 #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=; LL ql,qr,qk,cnt,ls[K],sum[K],pr[K];
bool pa[K];
void init(void)
{
for(int i=;i<=;i++)
if(!pa[i])
{
pr[cnt++]=i;
for(int j=i*;j<=;j+=i) pa[j]=;
}
}
LL sc(int t)
{
LL ans=;
for(LL i=ql;i<=qr;i++) sum[i-ql]=,ls[i-ql]=i;
for(int i=;i<cnt;i++)
{
for(LL j=max(2LL,(ql+pr[i]-)/pr[i])*pr[i];j<=qr;j+=pr[i])
{
LL cnt=;
while(ls[j-ql]%pr[i]==) ls[j-ql]/=pr[i],cnt++;
sum[j-ql]=(sum[j-ql]*(qk*cnt+))%mod;
}
}
for(LL i=ql;i<=qr;i++)
{
if(ls[i-ql]!=) sum[i-ql]=(sum[i-ql]*(qk+))%mod;
ans+=sum[i-ql];
if(ans>=mod) ans-=mod;
}
return ans;
} int main(void)
{
//freopen("in.acm","r",stdin);
int t;scanf("%d",&t);
init();
while(t--)
{
scanf("%lld%lld%lld",&ql,&qr,&qk);
printf("%lld\n",sc(t));
}
return ;
}

2017 Multi-University Training Contest - Team 4 hdu6069 Counting Divisors的更多相关文章

  1. 2017 Multi-University Training Contest - Team 4——HDU6069&&Counting Divisors

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6069 题目意思:首先解释一下d[n]这个函数表示n有多少个因子,百度一下可以知道这个函数是一个非完全积 ...

  2. 【2017 Multi-University Training Contest - Team 4】Counting Divisors

    [Link]:http://acm.hdu.edu.cn/showproblem.php?pid=6069 [Description] 定义d(i)为数字i的因子个数; 求∑rld(ik) 其中l,r ...

  3. 2017 Multi-University Training Contest - Team 9 1005&&HDU 6165 FFF at Valentine【强联通缩点+拓扑排序】

    FFF at Valentine Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  4. 2017 Multi-University Training Contest - Team 9 1004&&HDU 6164 Dying Light【数学+模拟】

    Dying Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  5. 2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】

    CSGO Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  6. 2017 Multi-University Training Contest - Team 9 1002&&HDU 6162 Ch’s gift【树链部分+线段树】

    Ch’s gift Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  7. 2017 Multi-University Training Contest - Team 9 1001&&HDU 6161 Big binary tree【树形dp+hash】

    Big binary tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  8. 2017 Multi-University Training Contest - Team 1 1003&&HDU 6035 Colorful Tree【树形dp】

    Colorful Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  9. 2017 Multi-University Training Contest - Team 1 1006&&HDU 6038 Function【DFS+数论】

    Function Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

随机推荐

  1. Git------pull出错解决方法

    1.图片 转载:http://www.2cto.com/os/201404/293183.html

  2. 调用组件的C++代码

    #include<stdio.h>#include "LJSummary.h"#include<iostream>int main(void){ print ...

  3. leetcode -- Permutations II TODO

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  4. JSON和对象之前的相互转换

    package com.jxjson.com; import android.util.Log; import org.json.JSONArray; import org.json.JSONExce ...

  5. Influxdb时序数据库阅读笔记

    时序数据库 2017年2月Facebook开源了beringei时序数据库:到了4月基于PostgreSQL打造的时序数据库TimeScaleDB也开源了,而早在2016年7月,百度云在其天工物联网平 ...

  6. Surface UEFI 菜单显示

    下载 Surface 的恢复映像   https://support.microsoft.com/zh-cn/surfacerecoveryimage UEFI 设置只能在系统启动时进行调整.若要加载 ...

  7. java如何发起一次http的post请求?

    @RequestMapping(value = "loginInSSO", method = RequestMethod.GET) public String loginInSSO ...

  8. ie8兼容:对象不支持“trim”属性或方法

    trim() 方法是原生js中去空格的方法,高版本浏览器已经默认支持trim() 方法,但ie8以下不支持,会报错:对象不支持“trim”属性或方法 解决这个的兼容,只需要扩展String原型属性 在 ...

  9. 理解CSS3 isolation: isolate的表现和作用

    转自:http://www.zhangxinxu.com/wordpress/?p=5155 只要元素可以创建层叠上下文,就可以阻断mix-blend-mode! 于是,不仅仅是isolation:i ...

  10. 背景图片拉伸显示CSS

    .divbackimg{ width:150px; height:50px; background-image:url(./btn.png); -moz-background-size: 100% 1 ...