题目链接

AtCoder:https://agc015.contest.atcoder.jp/tasks/agc015_f

洛谷:https://www.luogu.org/problemnew/show/AT2384

Solution

神仙结论题...窝只会打表找规律...

我们定义\(f(i,j)\)表示\((i,j)\)的\(\rm Euclidean\ step\ count\),也就是走多少步那个玩意。

定义\(Fib(n)​\)表示斐波那契数列第\(n​\)项,其中\(Fib(0)=Fib(1)=1​\)。

有一个比较显然(好找出规律)的结论:\(f(Fib(x),Fib(x+1))=x​\),且不存在任意\((i,j)​\)满足\(f(i,j)\geqslant x,i< Fib(x),j< Fib(x+1)​\),这个由(打表)数学归纳可得。

我们定义一个二元组\((x,y)​\)是好的,当且仅当不存在\((i,j)​\)满足\(i<x,j<y,f(i,j)>f(x,y)​\),显然只有好的二元组能贡献答案。

我们定义一个二元组\((x,y)​\)是优秀的,当且仅当\(x,y\leqslant Fib(v+2)+Fib(v-1)​\),其中\(v=f(x,y)​\)。

那么有一个结论:一个好的二元组进行一次\(\rm Euclidean\ step​\)之后一定为一个优秀的二元组,证明如下:

我们考虑反证法证明,设好的二元组为\((a,b)=(y,py+x)\)满足\(x\leqslant y,f(x,y)=v+1\),优秀的二元组为\((x,y)\),假设\(y> Fib(v+2)+Fib(v-1)\):

可得:\(a=y>Fib(v+2),b=py+x\geqslant x+y>Fib(v)+F(v+2)+Fib(v-1)=Fib(v+3)\)。

注意到\(f(Fib(v+2),Fib(v+3))=v+2>f(a,b)\),即存在\((a',b')\)满足\(a'>a,b'>b\)且\(f(a',b')>f(a,b)\),与\((a,b)\)是好的二元组矛盾。

打表可知优秀的二元组并不多,貌似是\(O(\log^2 n)​\)级别?我也不是特别清楚,所以我们可以把所有的优秀的二元组预处理出来,然后求答案就好了。

复杂度可能是\(O(q\log n)​\)...

#include<bits/stdc++.h>
using namespace std; #define int long long void read(int &x) {
x=0;int f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
} void print(int x) {
if(x<0) putchar('-'),x=-x;
if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');} #define lf double
#define ll long long const int maxn = 110;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7; #define pii pair<int,int >
#define fr first
#define sc second #define vec vector<pii >
#define mp make_pair
#define pb push_back #define iter vector <pii > :: iterator vec t[maxn];
int n,m,q,f[maxn]; signed main() {
t[1].pb(mp(1,2)),t[1].pb(mp(1,3)),t[1].pb(mp(1,4));
f[0]=f[1]=1;for(int i=2;i<=100;i++) f[i]=f[i-1]+f[i-2];
for(int i=1;i<=100;i++)
for(int j=0,l=t[i].size()-1;j<=l;j++) {
int x=t[i][j].sc,y=t[i][j].fr+x;
while(y<=f[i+3]+f[i]) t[i+1].pb(mp(x,y)),y+=x;
}read(q);
for(int i=1;i<=q;i++) {
read(n),read(m);if(n>m) swap(n,m);
int p=1,ans=0;
while(f[p+1]<=n&&f[p+2]<=m) p++;
printf("%lld ",p);
if(p==1) {write(n%mod*m%mod);continue;}
for(int j=0,l=t[p-1].size()-1;j<=l;j++) {
int x=t[p-1][j].fr,y=t[p-1][j].sc;
if(y<=n) ans=(ans+(m-x)/y)%mod;
if(y<=m) ans=(ans+(n-x)/y)%mod;
}write(ans);
}
return 0;
}

[AT2384] [agc015_f] Kenus the Ancient Greek的更多相关文章

  1. agc015F - Kenus the Ancient Greek(结论题)

    题意 题目链接 $Q$组询问,每次给出$[x, y]$,定义$f(x, y)$为计算$(x, y)$的最大公约数需要的步数,设$i \leqslant x, j \leqslant y$,求$max( ...

  2. agc015F Kenus the Ancient Greek

    题意: 有$Q$次询问,每次给定$X_i$和$Y_i$,求对于$1\leq x \leq X_i , 1 \leq y \leq Y_i$,$(x,y)$进行辗转相除法的步数的最大值以及取到最大值的方 ...

  3. Atcoder Grand Contest 015 F - Kenus the Ancient Greek(找性质+乱搞)

    洛谷题面传送门 & Atcoder 题面传送门 一道难度 Au 的 AGC F,虽然看过题解之后感觉并不复杂,但放在现场确实挺有挑战性的. 首先第一问很简单,只要每次尽量让"辗转相除 ...

  4. Atcoder训练计划

    争取三天做完一套吧,太简单的就写一句话题解吧(其实也没多少会做的). 自己做出来的在前面用*标记 agc007 *A - Shik and Stone 暴力dfs即可,直接判断个数 *B - Cons ...

  5. A&G¥C015

    A&G¥C015 A A+...+B Problem 正常A+B我还是会的,但是又加了个省略号就不会了/kk B Evilator 不会 C Nuske vs Phantom Thnook 以 ...

  6. POJ1151Atlantis 矩形面积并[线段树 离散化 扫描线]

    Atlantis Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21734   Accepted: 8179 Descrip ...

  7. 20151207Study

    Liberal lawmakers proposed a bill to reduce the cost of medicine for older Americans.自由主义立法者提出一条减少老年 ...

  8. hdu 1542 & & poj 1151

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  9. [POJ1151]Atlantis

    [POJ1151]Atlantis 试题描述 There are several ancient Greek texts that contain descriptions of the fabled ...

随机推荐

  1. 为centos虚拟机配置固定ip

    在virtual上安装centos虚拟机以后,发现虚拟机没有ip,无法联网 将虚拟机的网络适配器改为桥接模式,桥接到物理机的无线网卡 为虚拟机配置固定IP(vi /etc/sysconfig/netw ...

  2. wifi,Android渗透之arp欺骗

    查看自己wifi ip段 查看有哪些用户连接了此wifi,下图标记处为我的测试机(华为) 攻击开始,如果开启了arp防火墙,就会有提示 开启图片捕获

  3. maven摘除jar包中配置文件

    <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-p ...

  4. Shell重新学习(忘光了)

    成功和失败都放同一个文件 调试shell

  5. 第十三次作业psp

    psp 进度条 代码累积折线图 博文累积折线图 psp饼状图

  6. Daily Scrumming* 2015.10.31(Day 12)

    一.今明两天任务表 Member Today’s Task Tomorrow’s Task 江昊 学习rails的HTTP控制 继续学习rails等项目工具 杨墨犁 学习semanticUI的用法,配 ...

  7. Scapy 网段中ping扫描

    安装scapy pip3 install scapy-python3 交互式ip包构造 #scapy >>> ping = sr(IP(dst='202.100.1.1')/ICMP ...

  8. C++ MOOC

    相关课程列表: C++远征之起航篇 C++远征之离港篇 C++远征之封装篇 上 C++远征之封装篇 下 C++远征之继承篇 C++远征之多态篇 授课老师:james_yuan 在寒假,我主要选择 C+ ...

  9. 项目Beta冲刺(团队)第七天

    1.昨天的困难 服务器部署出了问题,本地服务器差点崩掉 运行一直闪退,在查找哪里出现问题的路上一去不复返 2.今天解决的进度 成员 进度 陈家权 消息功能模块 赖晓连 问答功能模块 雷晶 部署服务器到 ...

  10. self和super关键字介绍

    1.self和super OC提供两个保留字self 和 super ,用在方法定义中 OC语言中的self, 就相当于C++和Java中的this指针,学会使用self 首先要搞清楚属性这一概念以及 ...