HDU 6069 Counting Divisors
Counting Divisors
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1604 Accepted Submission(s): 592
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 :
In each test case, there are 3 integers l,r,k(1≤l≤r≤1012,r−l≤106,1≤k≤107).
1 5 1
1 10 2
1 100 3
48
2302
/*
* @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的更多相关文章
- 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(唯一分解定理+因子数)
http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 思路: 根据唯一分解定理,$n={a_{1}}^{p1}*{a2_{}}^{p2}...*{a_{ ...
- 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(区间素数筛法)
题意:...就题面一句话 思路:比赛一看公式,就想到要用到约数个数定理 约数个数定理就是: 对于一个大于1正整数n可以分解质因数: 则n的正约数的个数就是 对于n^k其实就是每个因子的个数乘了一个K ...
- 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 ...
- hdu 6069 Counting divisors 公式+区间筛
比赛的时候把公式扣出来了,,但是没有想到用筛法算公因子,,默默学习一下.. 题解:设n=p1^(c1)p2^{c2}...pm^{cm},n=p1^c1*p2^c2...p ...
随机推荐
- 已被.NET基金会认可的弹性和瞬态故障处理库Polly介绍
前言 本节我们来介绍一款强大的库Polly,Polly是一种.NET弹性和瞬态故障处理库,允许我们以非常顺畅和线程安全的方式来执诸如行重试,断路,超时,故障恢复等策略. Polly针对对.NET 4. ...
- Highway Networks
一 .Highway Networks 与 Deep Networks 的关系 深层神经网络相比于浅层神经网络具有更好的效果,在很多方面都已经取得了很好的效果,特别是在图像处理方面已经取得了很大的突破 ...
- C++移动构造函数以及move语句简单介绍
C++移动构造函数以及move语句简单介绍 首先看一个小例子: #include <iostream> #include <cstring> #include <cstd ...
- Next Greater Element I
You are given two arrays (without duplicates) nums1 and nums2 where nums1's elements are subset of n ...
- Android01-布局篇
在Android中,共有五种布局方式,分别是:LinearLayout(线性布局),FrameLayout(帧布局),AbsoluteLayout(绝对布局),RelativeLayout(相对布局) ...
- HAProxy安装文档
HAProxy安装文档 [toc][TOC] 一.环境说明 系统环境:CentOS Linux release 7.2.1511 (Core) 系统内核:3.10.0-327.el7.x86_64 软 ...
- ubuntu系统如何屏幕截图
我们知道,windows下有很多截图的软件和插件,那么在ubuntu系统下我们该怎样截图呢? 下面就让小编来告诉你几种简单的方法吧. 工具/原料 ubuntu系统电脑 方法一: 1.也许很多朋友都知道 ...
- JavaScript面向对象(OOP)
前 言 JRedu 面向对象程序设计(简称OOP)是现在最流行的程序设计方法,这种方法有别于基于过程的程序设计方法.在写面向对象的WEB应用程序方面JavaScript是一种很好的选择.它能支持 ...
- PHP Server Nginx 安装
1. PHP 安装: http://jingyan.baidu.com/article/b2c186c8f16d05c46ef6ff3c.html PHP 问题: http://www.cnblogs ...
- 转载:C#特性-表达式树
原文地址:http://www.cnblogs.com/tianfan/ 表达式树基础 刚接触LINQ的人往往觉得表达式树很不容易理解.通过这篇文章我希望大家看到它其实并不像想象中那么难.您只要有普通 ...