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* ...
随机推荐
- 前端 ---- jQuery的ajax
14-jQuery的ajax 什么是ajax AJAX = 异步的javascript和XML(Asynchronous Javascript and XML) 简言之,在不重载整个网页的情况下, ...
- 基于注解的Dubbo服务配置
基于注解的Dubbo服务配置可以大大减少dubbo xml配置文件中的Service配置量,主要步骤如下: 一.服务提供方 1. Dubbo配置文件中增加Dubbo注解扫描 <!-- ...
- Bootstrap 固定底部导航栏菜单
直接上代码: <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" ...
- Confluence 6 影响语言的其他设置
一个独立的用户可以在 Confluence 中选择应用到界面文字和消息中的语言.请注意,支持的语言类型基于在 Confluence 中安装的语言包. 你登录使用 Confluence 回话的语言基于下 ...
- day12 函数的嵌套调用 闭包函数,函数对象
函数嵌套: 函数嵌套: 嵌套指的是,一个物体包含另一个物体,函数嵌套就是一个函数包含另一个函数 按照函数的两个阶段 嵌套调用 指的是在函数的执行过程中调用了另一个函数,其好处可以简化外层大函数的代码, ...
- HTML&javaSkcript&CSS&jQuery&ajax(四)
一.HTML创建响应设计 Responsive Web Design 可以改变尺寸传递网页,对于平板和移动设备是必须的 1.<!DOCTYPE html><html lang=&qu ...
- 支付宝(查询对账单下载地址(alipay.data.dataservice.bill.downloadurl.query))
通过url下载zip对账单文件,进行解压,读取压缩文件内容. import java.io.BufferedOutputStream; import java.io.BufferedReader; i ...
- php 重要函数归集
1.json_encode 与 json_decode json_encode 把数组转化成字符串 json_encode(array) json_decode 把目标字符串转成数组json_deco ...
- 动手动脑——JAVA语法基础
EnumTest.java public class EnumTest { public static void main(String[] args) { Size s=Size.SMALL; Si ...
- AI学习吧-登录注册
登录注册注销 如果需要给表设置权限,没有登录就不可以查看,只需要在每个视图函数之前加上Auth_classes=[ ]即可! 增加两张表,做登录认证 #models.py #做登录验证 class U ...