hdu 6069 Counting Divisors 筛法
Counting Divisors
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
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
官方题解:
唯一分解定理
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stdlib.h>
#include<time.h>
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define bug(x) cout<<"bug"<<x<<endl; const int N=1e5+,M=1e6+,inf=;
const LL INF=1e18+,mod=; const int MAXN=;
int prime[MAXN];//保存素数
bool vis[MAXN];//初始化
int Prime(int n)
{
int cnt=;
memset(vis,,sizeof(vis));
for(int i=; i<n; i++)
{
if(!vis[i])
prime[cnt++]=i;
for(int j=; j<cnt&&i*prime[j]<n; j++)
{
vis[i*prime[j]]=;
if(i%prime[j]==)
break;
}
}
return cnt;
} LL num[M],ans[M]; int main()
{
int cnt=Prime();
int T;
scanf("%d",&T);
while(T--)
{
for(int i=; i<; i++)
num[i]=,ans[i]=;
LL l,r,K;
scanf("%lld%lld%lld",&l,&r,&K);
for(int q=; q<cnt; q++)
{
int i=prime[q];
LL L=(l%i==?l:(l/i+)*i);
for(LL j=L; j<=r; j+=i)
{
LL temp=j,base=;
int x=;
while(temp%i==)
{
x++;
temp/=i;
base*=i;
}
ans[j-l+]*=(1LL*K*x+)%mod;
ans[j-l+]%=mod;
num[j-l+]*=base;
}
}
for(LL i=l; i<=r; i++)
{
if(num[i-l+]!=i)
ans[i-l+]*=K+,ans[i-l+]%=mod;
}
LL out=;
for(LL i=l;i<=r;i++)
out+=ans[i-l+],out%=mod;
printf("%lld\n",out);
}
return ;
}
hdu 6069 Counting Divisors 筛法的更多相关文章
- 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
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(区间素数筛法)
题意:...就题面一句话 思路:比赛一看公式,就想到要用到约数个数定理 约数个数定理就是: 对于一个大于1正整数n可以分解质因数: 则n的正约数的个数就是 对于n^k其实就是每个因子的个数乘了一个K ...
- HDU 6069 Counting Divisors (素数+筛法)
题意:给定 l,r,k,让你求,其中 l <= r <= 1e12, r-l <= 1e6, k <= 1e7. 析:首先这个题肯定不能暴力,但是给定的区间较小,可以考虑筛选, ...
- 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 公式+区间筛
比赛的时候把公式扣出来了,,但是没有想到用筛法算公因子,,默默学习一下.. 题解:设n=p1^(c1)p2^{c2}...pm^{cm},n=p1^c1*p2^c2...p ...
- 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 ...
随机推荐
- webpack系统配置
简言之,webpack 是一个模块打包器 (module bundler),能够将任何资源如 JavaScript 文件.CSS 文件.图片等打包成一个或少数文件. 为什么要用Webpack? 首先, ...
- <转>jmeter(十二)关联之正则表达式提取器
本博客转载自:http://www.cnblogs.com/imyalost/category/846346.html 个人感觉不错,对jmeter讲解非常详细,担心以后找不到了,所以转发出来,留着慢 ...
- java中避免乱码
response.setContentType("text/html;charset=UTF-8"); 这个是在action中的 这个是在json中设置乱码的 contentTyp ...
- Powerpoint 演示时定时提醒工具
经常碰到这样的场景,规定的演讲报告时间所剩无几,甚至是已经超时,但演讲者并不知情,做为主持人只能从旁边轻轻的善意的提醒,但有时演讲者会没注意到主持人的提醒... 这里要介绍的就是这样一款用于提醒演讲者 ...
- Kattis之旅——Perfect Pth Powers
We say that x is a perfect square if, for some integer b, x = b2. Similarly, x is a perfect cube if, ...
- 【javascript】对原型对象、原型链的理解
原型对象,原型链这些知识属于基础类知识.但是平时开发过程中也很少用到. 看网上的意思,原型链用于es5开发场景下的继承.es6有了类语法糖之后,就自带继承了. 通过理解,个人画了一张原型链解构的关系图 ...
- Urllib库及cookie的使用
https://blog.csdn.net/pipisorry/article/details/47905781
- memset与malloc性能测试(转)
前一段跟同事聊项目组已有的一些工具,同事讲里面有太多的malloc与memset,对性能的影响比较大,因此今天就在自己的机器上测试了这两个函数,不多说,上数据.测试环境:2.2GHZ.2G内存mems ...
- python简说(十七)操作mysql数据库
import pymysqlconn = pymysql.connect(host='118.24.3.40',user='jxz',password='123456',port=3306,db='j ...
- 20145326蔡馨熤《网络对抗》—— Web基础
20145326蔡馨熤<网络对抗>—— Web基础 1.实验后回答问题 (1)什么是表单. 表单是一个包含表单元素的区域,表单元素是允许用户在表单中输入信息的元素,表单在网页中主要负责数据 ...