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的更多相关文章

  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. F. Geometrical Progression

    http://codeforces.com/problemset/problem/758/F F. Geometrical Progression time limit per test 4 seco ...

  3. CodeForces 567C Geometric Progression

    Geometric Progression Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  4. CodeForces 567C. Geometric Progression(map 数学啊)

    题目链接:http://codeforces.com/problemset/problem/567/C C. Geometric Progression time limit per test 1 s ...

  5. codeforces C. Arithmetic Progression 解题报告

    题目链接:http://codeforces.com/problemset/problem/382/C 题目意思:给定一个序列,问是否可以通过只插入一个数来使得整个序列成为等差数列,求出总共有多少可能 ...

  6. Codeforces 1114E - Arithmetic Progression - [二分+随机数]

    题目链接:http://codeforces.com/problemset/problem/1114/E 题意: 交互题,有一个 $n$ 个整数的打乱顺序后的等差数列 $a[1 \sim n]$,保证 ...

  7. Codeforces 567C - Geometric Progression - [map维护]

    题目链接:https://codeforces.com/problemset/problem/567/C 题意: 给出长度为 $n$ 的序列 $a[1:n]$,给出公比 $k$,要求你个给出该序列中, ...

  8. Codeforces 567C Geometric Progression(思路)

    题目大概说给一个整数序列,问里面有几个包含三个数字的子序列ai,aj,ak,满足ai*k*k=aj*k=ak. 感觉很多种做法的样子,我想到这么一种: 枚举中间的aj,看它左边有多少个aj/k右边有多 ...

  9. CodeForces 567C Geometric Progression 类似dp的递推统计方案数

    input n,k 1<=n,k<=200000 a1 a2 ... an 1<=ai<=1e9 output 数组中选三个数,且三个数的下标严格递增,凑成形如b,b*k,b* ...

随机推荐

  1. MySql 使用规范推荐(转)

    在java应用开发中深知数据库的重要性,绝大多数情况下数据库的性能决定了程序的性能,前期如果埋下的坑越多到后期会成为整个程序的瓶颈,所以希望java开发者一定要重视!!!! 一.基础规范 1.使用In ...

  2. Linux 安装Python和Django

    1.下载python源码包 网址: https://www.python.org/ 在Downloads中打开Source code 由于 Django1.11.15不兼容3.7版本的python 所 ...

  3. 初学python之路-day14

    一.带参装饰器 # 通常,装饰器为被装饰的函数添加新功能,需要外界的参数 # -- outer参数固定一个,就是func # -- inner参数固定同被装饰的函数,也不能添加新参数 # -- 可以借 ...

  4. css固定表头,表单内容可以滑动

    <html><head>    <meta charset="utf-8">    <title>Table</title&g ...

  5. python使用 HTMLTestRunner.py生成测试报告

    HTMLTestRunner.py python 2版本 下载地址:http://tungwaiyip.info/software/HTMLTestRunner.html 使用时,先建立一个”PyDe ...

  6. 第一周学习总结-Java

    2018年7月15日 暑假第一周,我从网上找了一些讲Java的视频,学到了一些Java的基础,同时也弥补了一些之前学c/c++的知识漏洞.例如,了解到了原码反码补码和按位取反运算符(~)的运算原理. ...

  7. 简单的做一个图片上传预览(web前端)

    转载:点击查看原文 在做web项目很多的时候图片都是避免不了的,所以操作图片就成了一个相对比较棘手的问题,其实也不是说很麻烦,只是说上传然后直接预览的过程很恶心,今天简单的做一个处理. 效果预览: & ...

  8. 开启或停止website

    1.添加:Microsoft.Web.Administration 2.代码: static void Main(string[] args) { var server = new ServerMan ...

  9. 【转】asp.net Core 系列【一】——创建Web应用

    ASP.NET Core 中的 Razor 页面介绍 Razor 页面是 ASP.NET Core MVC 的一个新功能,它可以使基于页面的编码方式更简单高效. 若要查找使用模型视图控制器方法的教程, ...

  10. Just oj 2018 C语言程序设计竞赛(高级组)H: CBT?

    H: CBT? 时间限制: 1 s      内存限制: 128 MB      提交 我的状态 题目描述 对于二叉树,如果这棵树的节点排布是按行从上到下,每行从左到右挨个放置,中间不会有空闲的节点. ...