原题地址:http://codeforces.com/contest/758/problem/F

F. Geometrical Progression

time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

For given n, l and r find the number of distinct geometrical progression, each of which contains n distinct integers not less than l and not greater than r. In other words, for each progression the following must hold: l ≤ ai ≤ r and ai ≠ aj , where a1, a2, ..., an is the geometrical progression, 1 ≤ i, j ≤ n and i ≠ j.

Geometrical progression is a sequence of numbers a1, a2, ..., an where each term after first is found by multiplying the previous one by a fixed non-zero number d called the common ratio. Note that in our task d may be non-integer. For example in progression 4, 6, 9, common ratio is .

Two progressions a1, a2, ..., an and b1, b2, ..., bn are considered different, if there is such i (1 ≤ i ≤ n) that ai ≠ bi.

Input

The first and the only line cotains three integers n, l and r (1 ≤ n ≤ 107, 1 ≤ l ≤ r ≤ 107).

Output

Print the integer K — is the answer to the problem.

Examples

Input

1 1 10

Output

10

Input

2 6 9

Output

12

Input

3 1 10

Output

8

Input

3 3 10

Output

2

Note

These are possible progressions for the first test of examples:

  • 1;
  • 2;
  • 3;
  • 4;
  • 5;
  • 6;
  • 7;
  • 8;
  • 9;
  • 10.

These are possible progressions for the second test of examples:

  • 6, 7;
  • 6, 8;
  • 6, 9;
  • 7, 6;
  • 7, 8;
  • 7, 9;
  • 8, 6;
  • 8, 7;
  • 8, 9;
  • 9, 6;
  • 9, 7;
  • 9, 8.

These are possible progressions for the third test of examples:

  • 1, 2, 4;
  • 1, 3, 9;
  • 2, 4, 8;
  • 4, 2, 1;
  • 4, 6, 9;
  • 8, 4, 2;
  • 9, 3, 1;
  • 9, 6, 4.

These are possible progressions for the fourth test of examples:

  • 4, 6, 9;
  • 9, 6, 4.

题意:给定 n, l and r ,求项数为n, 公比不为1,且数列每一项都属于[l,r]范围的不同的 等比数列 的个数。

题解:其实是先缩小范围然后直接枚举。

考虑数据范围1 ≤ n ≤ 107, 1 ≤ l ≤ r ≤ 10

设等比数列公比为d, d表示为 q/p,其中q或p为不同时等于1,且互质的正整数。

递增和递减数列的情况是成对出现的,即p和q互换。

所以不妨只考虑递增数列的情况,即公比d表示为q/p,其中pq互质,p为任意正整数,q>p,q为大于等于2的正整数。

则数列末项整除于qn-1 ,其中q>=2,2^24>10^7, 故n>=24时无解。

n=1时为结果为r-l+1, n=2时结果为(r-l+1)*(r-l),n>24时0.

n>=3&&n<24时,可以通过枚举出p和q的情况求解。

n>=3, 由于数列末项整除于qn-1 ,则qn-1 ≤ 107,即枚举 p,q的上界是(1071/(n-1),当n=3时,这个值为3162,可以通过暴力枚举实现。

枚举p,q,

每找到一对(p,q)且gcd(p,q)==1

考虑数列末项  an= a1*qn-1/pn-1  ,

要满足 a1>=l, an<=r 的范围条件,若 l*qn-1/pn-1 >r 则不满足题意,continue;

若 l*qn-1/pn-1 <=r 则有满足[l,r]范围的等比数列

现在求[l,r]范围,公比为q/p,项数为n的等比数列的个数。

数列各项为 a1, a1*q/p ……a1*qn-1/qn-1qn-1pn-1  /pn-1 /pn-1 pn-1q/pq/pq/pn-1 ,等比数列的个数即为a1可能的值。

末项为moa1*qn-1/ pn-1  所以a1必整除于pn-1 ,即a1可能的值为 [l,r*pn-1/qn-1]范围内可被 pn-1整除的, 即 (r*pn-1/qn-1)/pn-1-l/pn-1

#include <bits/stdc++.h>
#define LL long long
using namespace std; LL gcd(LL a, LL b){
if(b==) return a;
else return gcd(b,a%b);
} LL QuickPow(LL a, LL n){
LL ret=;
while(n){
if(n&) ret*=a;
a*=a;
n>>=;
}
return ret;
} LL l,r,n;
LL ans; int main()
{
cin>>n>>l>>r;
if(n>){
cout<<;return ;
}
if(n==){
cout<<r-l+;return ;
}
if(n==){
cout<<(r-l+)*(r-l);return ;
} //n>=3&&n<24的情况
LL upperlimit,pn,qn;
//p,q的枚举上界
upperlimit=pow(,double(log2(1e7+)/(n-))); //注意精度
for(LL p=;p<=upperlimit;p++)
for(LL q=p+;q<=upperlimit;q++)
if(gcd(p,q)==)
{
qn=QuickPow(q,n-);
pn=QuickPow(p,n-);
if(l*qn/pn>r) continue; //a1可能的值 :[l,r*pn/qn]范围内可被 pn整除的正整数,
ans+=(r*pn/qn)/pn-(l-)/pn;
}
//递增数列递减数列成对出现,只考虑了递增数列
cout<<ans*;
return ;
}

a1*qn-1/qn-1qn-1pn-1  /pn-1 /pn-1 pn-1q/pq/pq/pn-1 qn-1/qn-1qn-1pn-1  /pn-1 /pn-1 pn-1q/pq/pq/pn的

最新文章

  1. Spark官方文档 - 中文翻译
  2. Linux Gitlab
  3. System V IPC(3)-共享内存
  4. mycat配置日志
  5. 认清Linux中标准输入和标准输出的双重含义
  6. ASP.NET通用权限验证组件实现
  7. JavaScript 闭包环境非常奇特 - 相当于类与实例的关系?!
  8. uva 10118,记忆化搜索
  9. 【HTML5】Canvas
  10. 洛谷 P2590 [ZJOI2008]树的统计
  11. CF1139C Edgy Trees
  12. 记号一下selenium+Firefox自动下载的参数
  13. 认识js运动
  14. jquer文字闪烁简单实现
  15. 有多个.h引用时,不能有using namespace std
  16. leetcode50
  17. MFC+WinPcap编写一个嗅探器之五(过滤模块)
  18. IOS中的手势详解
  19. UVA-10615 Rooks (二分图匹配)
  20. centos安装图形操作界面

热门文章

  1. linux 之创建文件命令
  2. ArcMAP中如何将16位保存的卫星底图,转变为8位表示
  3. 【java】java反射机制,动态获取对象的属性和对应的参数值,并属性按照字典序排序,Field.setAccessible()方法的说明【可用于微信支付 签名生成】
  4. [置顶] 使用kube-proxy让外部网络访问K8S service的ClusterIP
  5. DatagramPacket,DatagramSocket
  6. WinSock基本知识
  7. 用MyEclipse2016 CI版创建一个SpringBoot程序
  8. perl学习笔记二
  9. 在项目中引用android.support.v7
  10. Angular 学习笔记——自定义指令之间的交互