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. 前端 ------ 03 body标签中的相关标签

    列表标签 <ul>.<ol>.<dl> 表格标签 <table> 表单标签 <form> 一.列表标签 列表标签分为三种. 1.无序列表&l ...

  2. MySQL建库建表

    一直使用SQL SERVER 数据库:最近项目使用MY SQL感觉还是有一点不适应.不过熟悉之后就会好很多. MY SQL 安装之后会有一个管理工具MySQL Workbench 感觉不太好用,数据库 ...

  3. Ex 2_34 线性3SAT..._第四次作业

  4. 【原创】大数据基础之Spark(9)spark部署方式yarn/mesos

    1 下载解压 https://spark.apache.org/downloads.html $ wget http://mirrors.shu.edu.cn/apache/spark/spark-2 ...

  5. push to origin/master was rejected错误解决方案

    idea中,发布项目到OSChina的Git中,当时按照这样的流程添加Git,然后push,提示:push to origin/master war rejected". 解决方案如下: 1 ...

  6. 一个简单的Loading控件

    实现效果如下: 使用方法: 在layout文件中添加以下代码: <com.example.jack.ui.widget.RingLoading android:layout_width=&quo ...

  7. 获取ScrollView ListView的当前位置的百分比

    找不到官方的API,就自己写了一下,下面是自己写的函数 --获取滚动层当前位置的百分比 function GetScrollViewPercent(scrollView) if scrollView ...

  8. python-元类的几种单例模式

    单例介绍: 单例即单个的实例,指的是同一个类实例化多次的结果都是指向同一个对象,用于节省内存空间 如果我们从配置文件中读取配置信息来进行实例化,在配置相同的情况下,就没必要重复产生对象浪费内存了. # ...

  9. Android 常用正则表达式

    前言 闲扯一下,已经有好久没更新博客了,记得上一篇博客的更新时间为 2017-05-12 15:20.截止到今天,超过一百天没更新了. 这篇博客的内容大多数是从别的博客摘抄过来的,写这篇博客的目的主要 ...

  10. PHP 转义

    函数名 释义 介绍 htmlspecialchars 将与.单双引号.大于和小于号化成HTML格式 &转成&"转成"' 转成'<转成<>转成> ...