【vijos】1543 极值问题(数论+fib数)
好神奇的一题。。
首先我竟然忘记n可以求根求出来,sad。
然后我打了表也发现n和m是fib数。。
严格证明(鬼知道为什么这样就能对啊,能代换怎么就能保证最大呢?):
(n^2-mn-m^2)^2=1
(m^2+mn-n^2)^2=1
(m(m+n)-n^2)^2=1
((m+n-n)(m+n)-n^2)^2=1
((m+n)^2-n(m+n)-n^2)^2=1
因为(n'^2-m'n'-m'^2)^2=1
取n'=m+n, m'=n使式子成立。。
所以每一次我们都能找到一个n'>n m'>m(假设了n>m),那么显然我们每次一直向上取,取到不能取为止
其实这题只需要找是否存在不是fib的数使得这个成立即可。
若n和m满足题意,那么gcd(n, m)=1,否则原式可以将d=gcd(n, m)提出来变为d*d(...)^2=1,此时(...)成了分数,显然不符合题意
而假设n>m,那么根据辗转相减有gcd(n, m)=gcd(m, n-m)
所以这样推下去,显然这些数就是fib数。
然后就是暴力就行了
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
#define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const ll max(const ll &a, const ll &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; } ll k, a, b, ans; int main() {
read(k);
ll n=1, m=0;
while(n+m<=k) {
ll c=m;
m=n;
n+=c;
}
printf("%lld\n", m*m+n*n);
return 0;
}
背景
小铭的数学之旅2。
描述
已知m、n为整数,且满足下列两个条件:
① m、n∈1,2,…,K
② (n^ 2-mn-m^2)^2=1
编一程序,对给定K,求一组满足上述两个条件的m、n,并且使m^2+n^2的值最大。例如,若K=1995,则m=987,n=1597,则m、n满足条件,且可使m^2+n^2的值最大。
格式
输入格式
输入仅一行,K的值。
输出格式
输出仅一行,m^2+n^2的值。
限制
每个测试点1秒。
提示
Source:
汕头市FXOI组
Phoeagon
ThanX2 Sivon
For TripleY
【vijos】1543 极值问题(数论+fib数)的更多相关文章
- hdu 1568 (log取对数 / Fib数通项公式)
hdu 1568 (log取对数 / Fib数通项公式) 2007年到来了.经过2006年一年的修炼,数学神童zouyu终于把0到100000000的Fibonacci数列 (f[0]=0,f[1]= ...
- VIJOS P1543极值问题
已知m.n为整数,且满足下列两个条件:① m.n∈1,2,…,K② (n^ 2-mn-m^2)^2=1编一程序,对给定K,求一组满足上述两个条件的m.n,并且使m^2+n^2的值最大.例如,若K=19 ...
- vijos - P1543极值问题(斐波那契数列 + 公式推导 + python)
P1543极值问题 Accepted 标签:[显示标签] 背景 小铭的数学之旅2. 描写叙述 已知m.n为整数,且满足下列两个条件: ① m.n∈1,2.-,K ② (n^ 2-mn-m^2)^2=1 ...
- HDOJ/HDU 1133 Buy the Ticket(数论~卡特兰数~大数~)
Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...
- 【动态规划】Vijos P1143 三取方格数(NOIP2000提高组)
题目链接: https://vijos.org/p/1143 题目大意: NxN的矩阵,每个值只能取一次,从(1,1)走到(n,n)走三次能取得的最大值. 题目思路: [动态规划] f[x1][y1] ...
- UVA 10312 - Expression Bracketing(数论+Catalan数)
题目链接:option=com_onlinejudge&Itemid=8&page=show_problem&problem=1253">10312 - Exp ...
- [Vijos 1143]三取方格数
Description 设有N*N的方格图,我们将其中的某些方格填入正整数, 而其他的方格中放入0. 某人从图得左上角出发,可以向下走,也可以向右走,直到到达右下角. 在走过的路上,他取走了方格中的数 ...
- bzoj 4772 显而易见的数论——拆分数(五边形数定理)+线性筛
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4772 题解:https://blog.csdn.net/Dream_Lolita/artic ...
- ACM数论-卡特兰数Catalan
Catalan 原理: 令h(0)=1,h(1)=1,catalan 数满足递归式: (其中n>=2) 另类递推公式: 该递推关系的解为: (n=1,2,3,...) 卡特兰数的应用实质上都是递 ...
随机推荐
- vue vue-router 使用注意事项
1.$router和$route区别 this.$router 访问路由器,实现路由的跳转等功能. this.$route 实现访问当前路由,$route.query (如果 URL 中有查询参数). ...
- javascript Array(数组)
迁移时间:2017年5月25日08:05:33 UpdateTime--2017年3月31日16:29:08 一.数组(Array) (一)用法 //js声明数组的两大类方式 // 第一类(通常使 ...
- 02-spring学习-配置bean
在spring的IOC容器中配置Bean 一,在xml中通过bean节点来配置bean: class:bean的类名,通过反射的方式在IOC容器中创建Bean,所以要求bean中必须有无参的构造器 i ...
- kettle--组件(2)--计算器
组件如下: 对计算类型的说明如下: The table below contains descriptions associated with the calculator step: Functio ...
- 微信小程序挑一挑辅助
1.窗体 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;usi ...
- mongodb - save()和insert()的区别
遇到_id相同的情况下:insert操作会报错:save完成保存操作 > db.person.find() > db.person.insert({"_id":1,ag ...
- 联想E440问题:点击鼠标时,弹出“无法连接synaptics定点装置驱动程序”错误
笔记本:Levono E440 问题描述: 在控制面板中,点击鼠标时,弹出“无法连接synaptics定点装置驱动程序”错误,如何解决? 即使在安装联想的驱动后,也没办法解决 解决步骤: 1. ...
- javascript和html中unicode编码和字符转义的详解
1.html中的转义:在html中如果遇到转义字符(如“ ”),不管你的页面字符编码是utf-8亦或者是GB2312,都会直接打印成相应的字符:而当遇到(如:“\u8981”[此处的8981是16进制 ...
- Atitit.异常的设计原理与 策略处理 java 最佳实践 p93
Atitit.异常的设计原理与 策略处理 java 最佳实践 p93 1 异常方面的使用准则,答案是:: 2 1.1 普通项目优先使用异常取代返回值,如果开发类库方面的项目,最好异常机制与返回值都提供 ...
- Real-Time SQL Monitoring using DBMS_SQLTUNE
Real-Time SQL Monitoring reports are available from three locations: Enterprise Manager - Click the ...