Counting Divisors

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

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
 
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6079 6078 6077 6076 6075 
/*
* @Author: Lyucheng
* @Date: 2017-08-03 13:13:45
* @Last Modified by: Lyucheng
* @Last Modified time: 2017-08-04 11:25:19
*/
/*
题意:给你一个区间[l,r]让你求区间内每个数的k次方因子数的总和 思路:比赛的时候想出来 i^k的因子是 (n1*k+1)*(n2*k+1)*...*(np*k+1),但是没想出来怎么优化,素数枚举
很烦,四场比赛每次差一点,比赛的时候想的是枚举[l,r]之间的数,优化到8300ms,实在没法优化了,应
该反过来想,枚举从[l,r]的素因子,因为i素因子的个数远小于i,大多数在sqrt i内,最多只有一个在sqrt i
之外。
*/
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> #define LL long long
#define mod 998244353
#define MAXN 1000005 using namespace std; int t;
LL l,r,k;
LL res;
LL d[MAXN];
LL pos[MAXN];
bool prime[MAXN];
LL p[MAXN];
int tol;
void init(){
tol=;
for(int i=;i<MAXN;i++){
prime[i]=true;
}
prime[]=prime[]=false;
for(int i=;i<MAXN;i++){
if(prime[i])
p[tol++]=(LL)i;
for(int j=;j<tol&&i*p[j]<MAXN;j++){
prime[i*p[j]]=false;
if((LL)i%p[j]==) break;
}
}
} int main(){
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
init();
scanf("%d",&t);
while(t--){
res=;
scanf("%I64d%I64d%I64d",&l,&r,&k);
for(LL i=l;i<=r;i++){
d[(int)(i-l)]=;
pos[(int)(i-l)]=i;
}
for(int i=;i<tol;i++){//枚举所有的素数
if(p[i]<=) continue;
LL cnt=(l+p[i]-)/p[i]*p[i];//找出[l,r]区间内的第一个p[i]的倍数
if(cnt-l<||cnt-l>r-l) continue;
for(int j=cnt-l;j<=r-l;j+=p[i]){
LL cur=;
while(pos[j]&&pos[j]%p[i]==){
cur++;
pos[j]/=p[i];
}
d[j]*=(cur*k+);
d[j]%=mod;
}
}
for(int i=;i<=r-l;i++){
if(pos[i]==)
res+=d[i];
else
res+=d[i]*(k+);
res%=mod;
}
printf("%I64d\n",res);
}
return ;
}

HDU 6069 Counting Divisors的更多相关文章

  1. hdu 6069 Counting Divisors(求因子的个数)

    Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Oth ...

  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 —— 2017 Multi-University Training 4

    Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Oth ...

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

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

  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. HDU 6069 Counting Divisors(区间素数筛法)

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

  8. 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 ...

  9. hdu 6069 Counting divisors 公式+区间筛

    比赛的时候把公式扣出来了,,但是没有想到用筛法算公因子,,默默学习一下.. 题解:设n=p1^(c1)p2^{c2}...pm^{cm},n=p​1^​c​1*​​​​p​2​^c​2​​​​...p ...

随机推荐

  1. 基于pytorch实现HighWay Networks之Train Deep Networks

    (一)Highway Networks 与 Deep Networks 的关系 理论实践表明神经网络的深度是至关重要的,深层神经网络在很多方面都已经取得了很好的效果,例如,在1000-class Im ...

  2. A glimpse of Support Vector Machine

    支持向量机(support vector machine, 以下简称svm)是机器学习里的重要方法,特别适用于中小型样本.非线性.高维的分类和回归问题.本篇希望在正篇提供一个svm的简明阐述,附录则提 ...

  3. 我的Spring学习记录(三)

    学习了AOP之后就可以应用一下了,所以这次我们了解一下Spring的声明式事务. 事务在我们的很多方面都可以体现,就拿我们平时的买卖活动,或者是银行的转账来说,这些活动要么是成功,要么是失败,比如:张 ...

  4. Java线程池详解

    一.线程池初探 所谓线程池,就是将多个线程放在一个池子里面(所谓池化技术),然后需要线程的时候不是创建一个线程,而是从线程池里面获取一个可用的线程,然后执行我们的任务.线程池的关键在于它为我们管理了多 ...

  5. spring boot系列01--快速构建spring boot项目

    最近的项目用spring boot 框架 借此学习了一下 这里做一下总结记录 非常便利的一个框架 它的优缺点我就不在这背书了 想了解的可以自行度娘谷歌 说一下要写什么吧 其实还真不是很清楚,只是想记录 ...

  6. spring框架总结(01)

    1.spring是什么? sprint其实就是一个开源框架,是于2003年兴起的一个轻量级的java开发框架,是有Road Johnson创建的,简单的来说spring是一个分层的JavaSE/EE( ...

  7. 简单又炫酷的two.js 二维动画教程

      前  言 S     N 今天呢给大家介绍一个小js框架,Two.JS.其实在自己学习的过程中并没有找到合适的教程,所以我这种学习延迟的同学是有一定难度的,然后准备给大家整理一份,简单易懂的小教程 ...

  8. 从入门到精通之Boyer-Moore字符串搜索算法详解

    本文讲述的是Boyer-Moore算法,Boyer-Moore算法作为字符串搜索算法,兴趣之下就想了解这个算法,发现这个算法一开始还挺难理解的,也许是我理解能力不是很好吧,花了小半天才看懂,看懂了过后 ...

  9. 技术领导(Technical Leader)画像

    程序员都讨厌被管理,而乐于被领导.管理的角色由PM(project manager)扮演,具体来说,PM负责提需求.改改改.大多数情况,PM是不懂技术的,这也是程序员觉得PM难以沟通的原因.而后者由技 ...

  10. 【DP】捡苹果

    #include<stdio.h> int max(int a,int b) { int c; if(a>b) c=a; else c=b; return c; } int main ...