题意

给定一个整数 $N$($1 \leq N \leq 10^{30}$),求最小的整数 $t$,要求 $t \geq N$,使得边长为 $t-1, t, t+1$ 的三角形面积为整数。

分析

根据海伦公式:$S = \sqrt{p(p-a)(p-b)(p-c)}$,$p = \frac{a+b+c}{2}$.

代入,令 $\frac{t}{2}=x$,化简得 $S^2 = 3x^2(x^2-1)$.

题目要求 $S$ 为整数,则 $(x^2-1)$ 一定是3乘以一个平方数,

即 $x^2-1=3y^2$,即 $x^2-3y^2=1$.

易知最小解为(2, 1),用递推式求出其他解即可。

由于题目 $N$ 的范围较大,到 1e30,可以使用 int128(1e38),本地测试1e38内,只有67个解。

#include<bits/stdc++.h>
using namespace std; const int maxn = +;
__int128 xx[maxn], yy[maxn]; void read(__int128 &x) {
x = ;
char ch;
int flag = ;
while (ch = getchar()) {
if (ch == '-') flag = -;
if (ch >= '' && ch <= '') break;
}
x = ch-'';
while ((ch = getchar()) >= '' && ch <= '') {
x = x* + ch-'';
}
x *= flag;
} void out(__int128 x) {
if (x < ) {
x = -x;
putchar('-');
}
if (x >= ) out(x / );
putchar(x % +'');
} void init()
{
xx[] = , yy[] = ;
for(int i = ;i <= ;i++)
{
xx[i] = xx[i-]* + yy[i-]*;
yy[i] = xx[i-] + yy[i-]*;
}
} int main()
{
init();
int T;
scanf("%d", &T);
while(T--)
{
__int128 n;
read(n);
for(int i = ;i <= ;i++)
{
if(xx[i]* >= n)
{
out(xx[i]*);
printf("\n");
break;
}
}
}
}

顺便记个int128的模板,

hdu6222——佩尔方程&&大数__int128的更多相关文章

  1. POJ1320 Street Numbers【佩尔方程】

    主题链接: http://poj.org/problem?id=1320 题目大意: 求解两个不相等的正整数N.M(N<M),使得 1 + 2 + - + N = (N+1) + - + M.输 ...

  2. POJ 1320 Street Numbers 【佩尔方程】

    任意门:http://poj.org/problem?id=1320 Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Su ...

  3. HDU 3292 【佩尔方程求解 && 矩阵快速幂】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=3292 No more tricks, Mr Nanguo Time Limit: 3000/1000 M ...

  4. POJ 1320 Street Numbers 解佩尔方程

    传送门 Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2529   Accepted: 140 ...

  5. 2010辽宁省赛G(佩尔方程)

    #include <iostream> #include <stdio.h> #include <string.h> #include <algorithm& ...

  6. C语言之基本算法26—佩尔方程求解

    //穷举法! /* ====================================================== 题目:求佩尔方程x*x-73*y*y=1的解. =========== ...

  7. [NBUT 1224 Happiness Hotel 佩尔方程最小正整数解]连分数法解Pell方程

    题意:求方程x2-Dy2=1的最小正整数解 思路:用连分数法解佩尔方程,关键是找出√d的连分数表示的循环节.具体过程参见:http://m.blog.csdn.net/blog/wh2124335/8 ...

  8. POJ 1320 Street Numbers(佩尔方程)

    Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3078   Accepted: 1725 De ...

  9. Problem G: 深入浅出学算法008-求佩尔方程的解

    Description 求关于x y的二次不定方程的解 x2-ny2=1 Input 多组输入数据,先输入组数T 然后输入正整数n(n<=100) Output 对于每组数据输出一行,求y< ...

随机推荐

  1. oracle--CRS-0215 : Could not start resource 'ora.node2.ons'.

    01,问题描述 安装10G+RAC集群,在node2进行vipca操作的时候发现这个问题 02,问题解决 原因是少了host的回环地址,当时删除错了 添加进去即可 127.0.0.1 localhos ...

  2. Python C++ OpenCV TensorFlow手势识别(1-10) 毕设 定制开发

    Python C++ OpenCV TensorFlow手势识别(1-10) 毕设 支持定制开发 (MFC,QT, PyQt5界面,视频摄像头识别) QQ: 3252314061 效果如下:

  3. 解决vue刷新页面以后丢失store的数据

    刷新页面时vue实例重新加载,store就会被重置,可以把定义刷新前把store存入本地localStorage.sessionStorage.cookie中,localStorage是永久储存,重新 ...

  4. ArrayList 源码分析 基于jdk1.8:

    1:数据结构: transient Object[] elementData;  //说明内部维护的数据结构是一个Object[] 数组 成员属性: private static final int ...

  5. MyBatis 通过 BATCH 批量提交

    本文由 简悦 SimpRead 转码, 原文地址 https://www.jb51.net/article/153382.htm 很多人在用 MyBatis 或者 通用 Mapper 时,经常会问有没 ...

  6. python网络爬虫(2)——scrapy框架的基础使用

    这里写一下爬虫大概的步骤,主要是自己巩固一下知识,顺便复习一下. 一,网络爬虫的步骤 1,创建一个工程 scrapy startproject 工程名称 创建好工程后,目录结构大概如下: 其中: sc ...

  7. Base64和本地以及在线图片互转

    package com.ruoyi.common.utils; import java.io.ByteArrayOutputStream; import java.io.FileInputStream ...

  8. ASP.NET Core 中的 Razor 文件编译

    asp .net core mvc 3.0 在编译的时候做了一些改变,有些view视图更改需要重新编译,你也可以配置运行时编译,不用每次更改都去重新生成,具体代码如下,从官方文档看到,做个记录. Ra ...

  9. 单片机成长之路(51基础篇) - 023 N76e003 系统时钟切换到外部时钟

    N76e003切换到外部时钟的资料很少(因为N76e003的片子是不支持无源晶振的,有源晶振的成本又很高,所以网上很少有对N76e003的介绍).有图有真相: 代码如下: main.c #includ ...

  10. java 获取真实ip地址

    /** * 获取真实ip地址 * @param request * @return */ public static String getIpAddress(HttpServletRequest re ...