F. Geometrical Progression
http://codeforces.com/problemset/problem/758/F
4 seconds
256 megabytes
standard input
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.
The first and the only line cotains three integers n, l and r (1 ≤ n ≤ 107, 1 ≤ l ≤ r ≤ 107).
Print the integer K — is the answer to the problem.
1 1 10
10
2 6 9
12
3 1 10
8
3 3 10
2
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的更多相关文章
- Codeforces Round #392 (Div. 2) F. Geometrical Progression
原题地址:http://codeforces.com/contest/758/problem/F F. Geometrical Progression time limit per test 4 se ...
- Codeforces 758F Geometrical Progression
Geometrical Progression n == 1的时候答案为区间长度, n == 2的时候每两个数字都可能成为答案, 我们只需要考虑 n == 3的情况, 我们可以枚举公差, 其分子分母都 ...
- 分析递归式 Solving Recurrences------GeeksforGeeks 翻译
在上一章中我们讨论了如何分析循环语句.在现实中,有很多算法是递归的,当我们分析这些算法的时候我们要找到他们的的递归关系.例如归并排序,为了排序一个数组,我们把它平均分为两份然后再重复平分的步骤.最后我 ...
- Mysql_以案例为基准之查询
查询数据操作
- 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 ...
- hdu 5278 Geometric Progression 高精度
Geometric Progression Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://bestcoder.hdu.edu.cn/contes ...
- Codeforces 1114 - A/B/C/D/E/F - (Undone)
链接:http://codeforces.com/contest/1114 A - Got Any Grapes? 题意:甲乙丙三个人吃葡萄,总共有三种葡萄:绿葡萄.紫葡萄和黑葡萄,甲乙丙三个人至少要 ...
- POJ3495 Bitwise XOR of Arithmetic Progression
Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 772 Accepted: 175 Description Write ...
- 在 C# 里使用 F# 的 option 变量
在使用 C# 与 F# 混合编程的时候(通常是使用 C# 实现 GUI,F#负责数据处理),经常会遇到要判断一个 option 是 None 还是 Some.虽然 Option module 里有 i ...
随机推荐
- Redis篇:单线程I/O模型
关注公众号,一起交流,微信搜一搜: 潜行前行 redis 单线程 I/O 多路复用模型 纯内存访问,所有数据都在内存中,所有的运算都是内存级别的运算,内存响应时间的时间为纳秒级别.因此 redis 进 ...
- SQLyog连接mysql8报2058错误
连接会话时,报如下错误. 通过网上查解决办法,报这个错误的原因是mysql密码加密方法变了 解决办法: 1.先使用mysql -uroot -p输入密码进去mysql 2.ALTER USER 'ro ...
- Erda 1.1 版本发布|3 大亮点特性最新解读
来源|尔达 Erda 公众号 Erda v1.1 Changelog: https://github.com/erda-project/erda/blob/master/CHANGELOG/CHA ...
- Elaticsearch(一)--基础原理及用法
一.基础概念 1.Elasticsearch简介 Lucene是Java语言编写的全文(全部的文本内容进行分析,建立索引,使之可以被搜索)检索引擎工具包(全文检索引擎的架构),用于处理纯文本的数据,提 ...
- 断言(assert)简介
java中的断言assert的使用 一.assertion的意义和用法 J2SE 1.4在语言上提供了一个新特性,就是assertion功能,他是该版本再Java语言方面最大的革新. 从理论上来说,通 ...
- Hive(四)【DML 数据导入导出】
目录 一.数据导入 1.1 [load]--向数据中装载数据 案例 1.2 [insert]--查询语句向表中插入数据 案例 1.3 [as select]--查询语句中创建表且加载数据 案例 1.4 ...
- 【Other】逻辑分析仪的使用(UART、SPI)
首先上一张接线示意图 上方是UART的接线方式,下方则是SPI的 事实上,这样接就能收到信号了 如果是SPI,要设定自己为主机,UART则没有这个问题 下面来说明逻辑分析仪的界面设定 设定介绍完了 下 ...
- VFL
VFL 1. 概念 VFL全称是Visual Format Language,翻译过来是"可视化格式语言" VFL是苹果公司为了简化Autolayout的编码而推出的抽象语言 2. ...
- 【Linux】【Services】【Package】yum
Linux程序包管理(2) CentOS: yum, dnf URL: ftp://172.16.0.1/pub/ YUM: yellow dog, Yellow ...
- AOP中环绕通知的书写和配置
package com.hope.utils;import org.aspectj.lang.ProceedingJoinPoint;import org.aspectj.lang.annotatio ...