原题地址: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的

Codeforces Round #392 (Div. 2) F. Geometrical Progression的更多相关文章

  1. Codeforces Round #485 (Div. 2) F. AND Graph

    Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...

  2. Codeforces Round #486 (Div. 3) F. Rain and Umbrellas

    Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  3. Codeforces Round #501 (Div. 3) F. Bracket Substring

    题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...

  4. map Codeforces Round #Pi (Div. 2) C. Geometric Progression

    题目传送门 /* 题意:问选出3个数成等比数列有多少种选法 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 */ /***************** ...

  5. Codeforces Round #499 (Div. 1) F. Tree

    Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...

  6. Codeforces Round #376 (Div. 2)F. Video Cards(前缀和)

    题目链接:http://codeforces.com/contest/731/problem/F 题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的 ...

  7. Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)

    题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...

  8. Codeforces Round #325 (Div. 2) F. Lizard Era: Beginning meet in the mid

    F. Lizard Era: Beginning Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  9. Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)

    题目地址:http://codeforces.com/contest/474/problem/F 由题意可知,最后能够留下来的一定是区间最小gcd. 那就转化成了该区间内与区间最小gcd数相等的个数. ...

随机推荐

  1. 开源 java CMS - FreeCMS2.3会员我的留言

    原文地址:http://javaz.cn/site/javaz/site_study/info/2015/29631.html​ 项目地址:http://www.freeteam.cn/ 我的留言 从 ...

  2. python 验证码识别之pytesser以及image学习记录

    一般的步骤就是上面这些,总的来说分为三部分,去除背景,分割字符,识别. 去除背景可以通过灰度化,二值化,去噪,倾斜度校正等(一般来说灰度化和二值化都是需要的,去噪和倾斜度看情况) 安装PIL工具,下载 ...

  3. nginx简单实现反向代理和静态资源服务器

    1修改hosts文件 127.0.0.1 www.test1.com 127.0.0.1 www.test2.com 127.0.0.1 static.com 2配置tomcat的server.xml ...

  4. python中pickle简介

    2017-04-10 pickle是用来加工数据的,可以用来存取结构化数据. 例如: 一个字典a = {'name':'Timmy','age':26},用pickle.dump存到本地文件,所存数据 ...

  5. [Functional Programming] Define Discrete State Transitions using the State ADT

    We build our first state transactions as two discrete transactions, each working on a specific porti ...

  6. 全民Scheme(1):数字游戏

    刚刚看到两句话,感觉不错,分享给大家: 1.用户的问题.就是我们的问题 2.做一些用户想要的东西 (define add1 (lambda (x) (+ 1 x))) (define sub1 (la ...

  7. 线程阻塞工具类:LockSupport(读书笔记)

     他可以在线程任意位置让线程阻塞, LockSupport的静态方法park()可以阻塞当前线程,类似的还有parkNanos() ParkUntil()等,他们实现了一个限时等待 public cl ...

  8. 非阻塞socket中read、write返回值

    read返回值 >0   读取数据的长度 =0   接收到对端发送的FIN,表示对端的写端关闭. <0   如果errno=EINTR.收到信号并从信号处理函数返回时,慢系统调用会返回并设 ...

  9. (六)Thymeleaf的 th:* 属性之—— th: ->text& utext& href

    th:*使用原因: for the sake of simplicity and compactness of the code samples(简化代码) the th:*notation is m ...

  10. ios程序,顶部和底部产生空白——程序不能全屏运行

    在开发过程中,遇到过这样的问题,整个程序不能以全屏状态运行,顶部和底部出现空白,如下图所示: 这样的原因是:设置的启动页不合适,设置大小合适的启动页就好了