http://codeforces.com/problemset/problem/758/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.
  • 题意:在[l,r]区间中找项数为n的等比数列的不同个数;

思路:首先讨论下 n = 1,2的情况,然后,找公比,应为r<=1e7,那么n不会超过23,当d为整数的时候那么d^(n-1)<=r;

从而选出d,然后当d为分数的时候,假设(a/b);那么我们只要枚举(a,b互质)的数,因为若不互质可化成互质,那么(a/b)^(n-1),假设第一个数为x,那么x要是b^(n-1)的

倍数,设x = k*(b)^(n-1);那么a,b必定是刚选出来的那些数中的数,不可能比选出来的数大,因为x = k*(b)^(n-1)<=r&&k*(b)^(n-1)<=n&&(k>=1);

那么枚举d来解k的范围;(l-1)< (a)^(n-1)*k&&k*(b^(n-1))<=r;

 1 #include<bits/stdc++.h>
2 using namespace std;
3 typedef long long LL;
4 LL gcd(LL n,LL m){if(m == 0)return n;return gcd(m,n%m);}
5 LL ans[4000];
6 int main(void)
7 {
8 LL n,l,r;LL ask = 0;
9 scanf("%lld %lld %lld",&n,&l,&r);
10 if(n == 1)
11 printf("%lld\n",r-l+1);
12 else if(n == 2)
13 printf("%lld\n",(LL)(r-l+1)*(LL)(r-l));
14 else if(n > 25)
15 printf("0\n");
16 else
17 { int cn = 0;
18 for(int i = 1;i <= 4000;i++)
19 { LL sum = 1;int j;
20 for( j = 0;j < n-1;j++)
21 {
22
23 sum*=(LL)i; if(sum > r)break;
24 }
25 if(j == n-1)
26 {
27 ans[++cn] = sum;
28 }
29 else break;
30 }
31 for(int i = 1;i <= cn;i++)
32 {
33 for(int j = i+1;j <= cn;j++)
34 {
35 if(gcd(i,j) == 1)
36 {
37 LL p = r/ans[j];
38 LL q = (l-1)/ans[i];
39 if(p >= q)
40 ask+=p-q;
41 }
42 }
43 }
44 printf("%lld\n",ask*(LL)2);
45 }
46 return 0;
47 }

F. Geometrical Progression的更多相关文章

  1. Codeforces Round #392 (Div. 2) F. Geometrical Progression

    原题地址:http://codeforces.com/contest/758/problem/F F. Geometrical Progression time limit per test 4 se ...

  2. Codeforces 758F Geometrical Progression

    Geometrical Progression n == 1的时候答案为区间长度, n == 2的时候每两个数字都可能成为答案, 我们只需要考虑 n == 3的情况, 我们可以枚举公差, 其分子分母都 ...

  3. 分析递归式 Solving Recurrences------GeeksforGeeks 翻译

    在上一章中我们讨论了如何分析循环语句.在现实中,有很多算法是递归的,当我们分析这些算法的时候我们要找到他们的的递归关系.例如归并排序,为了排序一个数组,我们把它平均分为两份然后再重复平分的步骤.最后我 ...

  4. Mysql_以案例为基准之查询

    查询数据操作

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

    C. Geometric Progression Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  6. hdu 5278 Geometric Progression 高精度

    Geometric Progression Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contes ...

  7. Codeforces 1114 - A/B/C/D/E/F - (Undone)

    链接:http://codeforces.com/contest/1114 A - Got Any Grapes? 题意:甲乙丙三个人吃葡萄,总共有三种葡萄:绿葡萄.紫葡萄和黑葡萄,甲乙丙三个人至少要 ...

  8. POJ3495 Bitwise XOR of Arithmetic Progression

    Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 772   Accepted: 175 Description Write ...

  9. 在 C# 里使用 F# 的 option 变量

    在使用 C# 与 F# 混合编程的时候(通常是使用 C# 实现 GUI,F#负责数据处理),经常会遇到要判断一个 option 是 None 还是 Some.虽然 Option module 里有 i ...

随机推荐

  1. Linux之crond任务调度

    1. 示意图 2. 基本语法 crontab [选项] # -e : 编辑crontab定时任务 # -l : 查询crontab # -r : 删除当前用户所有的crontab任务 # 例子: # ...

  2. Prometheus基础

    监控系统作用 监控系统主要用于保证所有业务系统正常运行, 和业务的瓶颈监控. 需要周期性采集和探测. 采集的详情 采集: 采集器, 被监控端, 监控代理, 应用程序自带仪表盘, 黑盒监控, SNMP. ...

  3. day20 系统优化

    day20 系统优化 yum源的优化 yum源的优化: 自建yum仓库 使用一个较为稳定的仓库 # 安装华为的Base源 或者使用清华的源也可以 wget -O /etc/yum.repos.d/Ce ...

  4. webservice--cxf和spring结合

    服务端: 实体: package entity; import java.util.Date; /*** 实体 */ public class Pojo { //温度 private String d ...

  5. @RequestBody配合@Valid 校验入参参数

    自定义一个Controller import com.example.demo.pojo.User; import org.springframework.web.bind.annotation.Po ...

  6. Output of C++ Program | Set 1

    Predict the output of below C++ programs. Question 1 1 // Assume that integers take 4 bytes. 2 #incl ...

  7. hadoop基本命令(转)

    在这篇文章中,我们默认认为Hadoop环境已经由运维人员配置好直接可以使用. 假设Hadoop的安装目录HADOOP_HOME为/home/admin/hadoop. 启动与关闭 启动HADOOP 进 ...

  8. MySQL(1):SQLyog

    数据库(DataBase,简称DB) 一. 基本数据库操作命令 flush privileges 刷新数据库 show databases 显示所有数据库 use dbname 打开某个数据库 sho ...

  9. C语言编辑链接

    库函数(Library Files)库函数就是函数的仓库,它们都经过编译,重用性不错.通常,库函数相互合作,来完成特定的任务.比如操控屏幕的库函数(cursers和ncursers库函数),数据库读取 ...

  10. Oracle 表结构管理

    表其实是数据的'容器'.oracle有几种类型的表: 普通表(ordinary table)又叫堆组织表. 聚簇表(clustered table) 分区表(partition table) 外部表( ...