Codeforces 758F Geometrical Progression
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 longusing namespace std;const int N = 1e5 + 7; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; const double eps = 1e-6; const double PI = acos(-1);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 = 1;while(b) {if(b & 1) ans = ans * a;a = a * a; b >>= 1;}return ans; } int main() {scanf("%d%d%d", &n, &l, &r);if(n > 25) {puts("0");} else if(n == 1) {printf("%d\n", r - l + 1);} else if(n == 2) {printf("%lld\n", 1ll * (r - l + 1) * (r - l));} else {for(int i = 1; i * i <= r; i++) {for(int j = 1; 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 = 0;for(auto& t : vc) {LL x = t.x, y = t.y;bool flag = true;for(int i = 3; i <= n; i++) {y = y * t.y;if(y > r) {flag = false;break;}}if(!flag) continue;for(int i = 3; i <= n; i++) {x = x * t.x;if(x > 10000000LL * y) {flag = false;break;}}if(!flag) continue;int Ly = ((l - 1) / y) + 1, Ry = r / y;int Lx = ((l - 1) / x) + 1, 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 + 1;}printf("%lld\n", ans);}return 0; }/* 3 1 10000000 */
转载于:https://www.cnblogs.com/CJLHY/p/10618699.html
Codeforces 758F Geometrical Progression相关推荐
- [CodeForces 567C] Geometric Progression
题目链接:http://codeforces.com/problemset/problem/567/C AC代码: /** 枚举中值a[i],然后开一个mp1维护中值前的a[i]/k这个数的个数,* ...
- 有趣题目和认知合集(持续更新)
写写对一些算法的理解,挂几个有意思的题,可能也会挂几个板子题 算法理解偏向于能懂即可,没有严格的证明 快乐几何 [1.2]Volatile Kite 点到直线 快乐搜与暴力 [2.4]Short Co ...
- 一个极具误导性的数学术语汉译名——几何级数
目录 1. 提出问题 2. "geometric progression"的英语解释 1. 提出问题 由于历史原因和学术规则的原因,很多数学术语的汉语译名给读者造成了长期的困惑,让 ...
- map Codeforces Round #Pi (Div. 2) C. Geometric Progression
题目传送门 1 /* 2 题意:问选出3个数成等比数列有多少种选法 3 map:c1记录是第二个数或第三个数的选法,c2表示所有数字出现的次数.别人的代码很短,思维巧妙 4 */ 5 /******* ...
- 【CodeForces - 255C】Almost Arithmetical Progression (dp,离散化)
题干: Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he ca ...
- Codeforces Round #224 (Div. 2): C. Arithmetic Progression(模拟)
题意: 给你n个数字,你需要再添加一个数字,使得最后所有数字排序之后任意相邻两个数之差全部相等,问可以添加多少种不同的数字 思路: 一看就是水题但是情况不少,没了 例如所有数字全部相等,只有两个数字, ...
- Codeforces Round #481 (Div. 3)【完结】
2022.3.1 题目地址:https://codeforces.com/contest/978 目录 A. Remove Duplicates[模拟] B. File Name[贪心 / 双指针] ...
- Codeforces Round #538 (Div. 2) (CF1114)
Codeforces Round #538 (Div. 2) (CF1114) 今天昨天晚上的cf打的非常惨(仅代表淮中最低水平 先是一路缓慢地才A掉B,C,然后就开始杠D.于是写出了一个O( ...
- CodeForces 375D Tree and Queries
传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...
- 「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)
题意与分析(CodeForces 540D) 是一道概率dp题. 不过我没把它当dp做... 我就是凭着概率的直觉写的,还好这题不算难. 这题的重点在于考虑概率:他们喜相逢的概率是多少?考虑超几何分布 ...
最新文章
- C# 读取 appconfig文件配置数据库连接的方法
- python怎么把数据写入txt-python(如何将数据写入本地txt文本文件)
- Winform中使用代码编写Button按钮的点击事件
- QT编程中遇到的问题总结
- 【转】微软Azure Functions使用入门
- u-boot,linux,文件系统移植笔记1
- 因市场垄断 高通被欧盟开出巨额罚单 高通:我不服
- BroadLeaf项目搜索功能改进
- (转)Django ==== 实战学习篇二 需求分析及设计,创建第一个模型---购物车的应用...
- Uva 10306 e-Coins
- 高效办公之Windows高效技巧提高你的工作效率
- Flutter 图片透明度(光暗程度)
- 初次Blender建模遇到的问题与解决方法
- Linux系统基于MobaXterm的下载及使用
- 大话数据结构——烂笔头
- 在PB中存图片入数据库及显示图片
- 我的世界服务器显示弹幕,[娱乐]RaiixDM —— 在mc中接收b站直播弹幕[1.12.x-1.15.x]...
- git - - - .gitignore
- EditPlus中文版-具有 FTP、FTPS 和 sftp 功能的文本编辑器
- UDT 最新源码分析(三) -- UDT Socket 相关函数
热门文章
- Java-20180419
- 《Python分布式计算》第2章 异步编程 (Distributed Computing with Python)
- centos更新163源并升级内核
- Python 模块,包与分发
- Expression Blend实例中文教程(11) - 视觉管理器快速入门Visual State Manager(VSM)
- Ubuntu使用零碎记录
- 2015(4)软件工程,软件运行与维护,新旧系统转换策略,遗留系统的演化策略,数据转换与数据迁移...
- 流畅的Python---list排序和保持有序序列
- fastdfs安装部署
- jar包的生成及运行