Codeforces 758F Geometrical Progression
n == 1的时候答案为区间长度, n == 2的时候每两个数字都可能成为答案,
我们只需要考虑 n == 3的情况, 我们可以枚举公差, 其分子分母都在sqrt(1e7)以内,
然后暴力枚举就好啦。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n, l, r; struct Node {
int x, y;
bool operator < (const Node& rhs) const {
return x * rhs.y < rhs.x * y;
}
bool operator == (const Node& rhs) const {
return x * rhs.y == rhs.x * y;
}
}; vector<Node> vc; int Power(int a, int b) {
int ans = ;
while(b) {
if(b & ) ans = ans * a;
a = a * a; b >>= ;
}
return ans;
}
int main() {
scanf("%d%d%d", &n, &l, &r);
if(n > ) {
puts("");
} else if(n == ) {
printf("%d\n", r - l + );
} else if(n == ) {
printf("%lld\n", 1ll * (r - l + ) * (r - l));
} else {
for(int i = ; i * i <= r; i++) {
for(int j = ; j * j <= r; j++) {
if(i == j) continue;
int x = i, y = j;
int gcd = __gcd(x, y);
vc.push_back(Node{x / gcd, y / gcd});
}
}
sort(vc.begin(), vc.end());
vc.erase(unique(vc.begin(), vc.end()), vc.end());
LL ans = ;
for(auto& t : vc) {
LL x = t.x, y = t.y;
bool flag = true;
for(int i = ; i <= n; i++) {
y = y * t.y;
if(y > r) {
flag = false;
break;
}
}
if(!flag) continue;
for(int i = ; i <= n; i++) {
x = x * t.x;
if(x > 10000000LL * y) {
flag = false;
break;
}
}
if(!flag) continue; int Ly = ((l - ) / y) + , Ry = r / y;
int Lx = ((l - ) / x) + , Rx = r / x;
if(Ly > Ry) continue;
if(Lx > Rx) continue;
if(Lx > Ry) continue;
if(Rx < Ly) continue;
Lx = max(Lx, Ly);
Rx = min(Rx, Ry);
ans += Rx - Lx + ;
}
printf("%lld\n", ans);
}
return ;
} /*
3 1 10000000
*/
Codeforces 758F 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 ...
- F. Geometrical Progression
http://codeforces.com/problemset/problem/758/F F. Geometrical Progression time limit per test 4 seco ...
- CodeForces 567C Geometric Progression
Geometric Progression Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- CodeForces 567C. Geometric Progression(map 数学啊)
题目链接:http://codeforces.com/problemset/problem/567/C C. Geometric Progression time limit per test 1 s ...
- codeforces C. Arithmetic Progression 解题报告
题目链接:http://codeforces.com/problemset/problem/382/C 题目意思:给定一个序列,问是否可以通过只插入一个数来使得整个序列成为等差数列,求出总共有多少可能 ...
- Codeforces 1114E - Arithmetic Progression - [二分+随机数]
题目链接:http://codeforces.com/problemset/problem/1114/E 题意: 交互题,有一个 $n$ 个整数的打乱顺序后的等差数列 $a[1 \sim n]$,保证 ...
- Codeforces 567C - Geometric Progression - [map维护]
题目链接:https://codeforces.com/problemset/problem/567/C 题意: 给出长度为 $n$ 的序列 $a[1:n]$,给出公比 $k$,要求你个给出该序列中, ...
- Codeforces 567C Geometric Progression(思路)
题目大概说给一个整数序列,问里面有几个包含三个数字的子序列ai,aj,ak,满足ai*k*k=aj*k=ak. 感觉很多种做法的样子,我想到这么一种: 枚举中间的aj,看它左边有多少个aj/k右边有多 ...
- CodeForces 567C Geometric Progression 类似dp的递推统计方案数
input n,k 1<=n,k<=200000 a1 a2 ... an 1<=ai<=1e9 output 数组中选三个数,且三个数的下标严格递增,凑成形如b,b*k,b* ...
随机推荐
- MD5加密算法工具类
import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorith ...
- Linux/Ubuntu安装搜狗输入法
零.你首先需要安装fcitx小企鹅输入法,相信绝大部分用linux的中国人都用这个输入法,安装fcitx后同时还能解决Sublime Text的中文输入问题. 安装fcitx输入法前首先要安装fcit ...
- [JavaScript]iframe的contentWindow
HTMLIFrameElement.contentWindow返回的是HTMLIFrameElement类型元素的window对象 通过此对象可以修改iframe实体内的window行为 <if ...
- LINUX-redis & mongodb
ubuntu安装redis: apt-get -y install redis-serverubuntu启动redis: /etc/init.d/redis-server restart linux安 ...
- redhat7.3安装yum源
#检查rehat自带的yum源[root@localhost ~]# rpm -qa | grep yum -.el7.noarch -.el7.noarch -.el7.noarch -.el7.n ...
- java+appium 自动化环境搭建
1.安装JDK1.7及以上 2.下载解压sdk并且配置环境变量: ANDROID_HOME:...\adt-bundle-windows-x86_64-20140702\sdk PATH:%ANDRO ...
- Modbus库开发笔记之十一:关于Modbus协议栈开发的说明
对于Modbus协议栈的整个开发内容,前面已经说得很清楚了,接下来我们说明一下与开发没有直接关系的内容. 首先,关于我为什么开发这个协议栈的问题.我们的初衷只是想能够在开发产品时不用每次都重写这一部分 ...
- 在 Confluence 中启用 HTTP 响应压缩
Confluence 能够支持 HTTP 的 GZip 传输编码.这个意味着 Confluence 将可以把数据压缩后传输给用户,这种配置能够针对不稳定的互联网状态下的传输速度缓慢和不稳定并且能够降低 ...
- Confluence 6 配置管理员会话的安全
Confluence 通过使用 Confluence administration console 来显示管理员访问后台管理的功能或者管理一个空间.当一个 Confluence 管理员(以管理员身份登 ...
- Confluence 6 通过 SSL 或 HTTPS 运行 - 确定你的证书路径
在默认的情况下,Tomcat 希望 keystore 文件被命名为 .keystore 文件,同时这个文件应该放置在 Tomcat 运行的 home 目录中(这个目录可能与你自己的 Home 目录的路 ...