HDU 6069
Counting Divisors
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
#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的更多相关文章
- HDU 6069 Counting Divisors(唯一分解定理+因子数)
http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 思路: 根据唯一分解定理,$n={a_{1}}^{p1}*{a2_{}}^{p2}...*{a_{ ...
- 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 筛法
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
- 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. 析:首先这个题肯定不能暴力,但是给定的区间较小,可以考虑筛选, ...
- Counting Divisors HDU - 6069
设n=p_1^{c_1}p_2^{c_2}...p_m^{c_m}n=p1c1p2c2...pmcm,则d(n^k)=(kc_1+1)(kc_2+1)...( ...
- [hdu 6069]素数筛+区间质因数分解
给[L,R]区间的每一个数都质因数分解的复杂度可以达到(R-L)logR,真的涨姿势…… 另外,质因数分解有很重要的一点,就是只需要打sqrt(R)以内的素数表就够了……因为超过sqrt(R)的至多只 ...
- HDU 6069 Counting Divisors(区间素数筛法)
题意:...就题面一句话 思路:比赛一看公式,就想到要用到约数个数定理 约数个数定理就是: 对于一个大于1正整数n可以分解质因数: 则n的正约数的个数就是 对于n^k其实就是每个因子的个数乘了一个K ...
随机推荐
- w3c编程挑战-初级脚本算法
之前偶然看到了w3c上的编程挑战题,就像拿来试试手,先做的是初级脚本算法,总体不难,如果有更好的方法,希望能一起交流! 1.翻转字符串 先把字符串转化成数组,再借助数组的reverse方法翻转数组顺序 ...
- [HNOI2009]梦幻布丁 算法技巧之邻接链
题目描述 N个布丁摆成一行,进行M次操作.每次将某个颜色的布丁全部变成另一种颜色的,然后再询问当前一共有多少段颜色.例如颜色分别为1,2,2,1的四个布丁一共有3段颜色. 输入输出格式 输入格式: 第 ...
- golang 私钥"加密"公钥"解密"
---恢复内容开始--- 之前工作主要使用C/C++与银行/第三方支付对接,但C/C++无法满足客户"当天给协议明天实盘上载"的开发速度以及现公司一些特殊情况,所以决定用go来 ...
- test_markdown
add modifications 非科学计数法显示数字 citation[^ref1] format bank% do not use scientific expression format lo ...
- vue1与vue2的路由 以及vue2项目大概了解
vue1的路由 1.设置根组件 Vue.extend() 2.设置局部组件 Vue.extend({template:"/home"}) 3.实例化路由 var route ...
- [leetcode-604-Design Compressed String Iterator]
Design and implement a data structure for a compressed string iterator. It should support the follow ...
- [leetcode-530-Minimum Absolute Difference in BST]
Given a binary search tree with non-negative values, find the minimum absolute difference between va ...
- css 背景图片自适应
body{ height:100%; overflow:hidden;} .bg { background-image: url(../../img/beijing.jpg); width:100%; ...
- 理解oauth2.0【转载】
原文出处: http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html OAuth是一个关于授权(authorization)的开放网络标准,在全世界得 ...
- ASP搜索查询
html code: <form name="frm_Search" method="get" action="Search.asp" ...