hdu6222(佩尔方程+大数)

求最小的大于等于n的t,使得t-1,t,t+1围成的三角形面积是整数

要使s^2是整数,就要使3*(x^2-1)是平方数,也就要使(x^2-1) = 3*y^2

整理得到x^2-3*y^2 = 1

然后用__int128搞一下就行了

#include <cstdio>
#include <cstring>
#include <ctime> 
#include <algorithm>
using namespace std;
const int mx = 105;
__int128 ans[mx][2];
void read(__int128 &x) {
	x = 0;
	char ch;
	int flag = 1;
	while (ch = getchar()) {
		if (ch == '-') flag = -1;
		if (ch >= '0' && ch <= '9') break;
	}
	x = ch-'0';
	while ((ch = getchar()) >= '0' && ch <= '9') {
		x = x*10 + ch-'0';
	}
	x *= flag;
}

void out(__int128 x) {
	if (x < 0) {
		x = -x;
		putchar('-');
	}
	if (x >= 10) out(x / 10);
	putchar(x % 10 +'0');
}

int main() {
	ans[1][0] = 2; ans[1][1] = 1;
	for (int i = 2; i <= 100; i++) {
		ans[i][0] = ans[i-1][0]*ans[1][0] + 3*ans[i-1][1]*ans[1][1];
		ans[i][1] = ans[i-1][0]*ans[1][1] + ans[i-1][1]*ans[1][0];
	}
	int T;
	scanf("%d", &T);
	
	while (T--) {
		__int128 n;
		read(n);
		for (int i = 1; i <= 100; i++) {
			if (ans[i][0]*2 >= n) {
				out(ans[i][0]*2);
				puts("");
				break;
			}
		}
	}
	
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值