比赛 2022级数学专题练习赛5 评测结果 AAWWWAAAAA
题目名称 Pell方程 最终得分 70
用户昵称 op_组撒头屯 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2023-01-09 20:49:35
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define si set<int>
#define qi queue<int>
#define sti stack<int>
#define fi first
#define se second
#define pb push_back
const int N=10000000+5;
ll calc(ll x,ll lim){
    ll l=1,r=lim;
    while(l<r){
        ll mid=(l+r+1)/2;
        if (mid*mid<=x)l=mid;
        else r=mid-1;
    }
    return l;
}
int main(){
	freopen ("pell.in","r",stdin);
	freopen ("pell.out","w",stdout);
	ll n;scanf("%lld",&n);
	for (ll k=1;;k++){
	    ll y=n*k*k-2*k;
	    ll s=calc(y,k*n-1);
	    if (s*s==y){
	        printf("%lld %lld\n",k*n-1,s);return 0;
        }
        y=n*k*k+2*k;
	    s=calc(y,k*n+1);
	    if (s*s==y){
	        printf("%lld %lld\n",k*n+1,s);return 0;
        }
    }
    printf("genshin\n");
    return 0;
}