CSP-J倒计时1天。
最近教练给我们做了10+
套模拟赛,疯狂整理后,每套模拟都写了1~2
篇题解。
广刷题,确实有用,今天早上做出来一道第二题题目传送门
顺便在这放个题解
化简
decode
\(n = p \times q\)
\(e \times d = (p - 1)(q - 1) + 1\)
令\(x = e \times d - 2\)
则\(x = p \times q - (p + q)\)
因为,\(p \times q\),且\(x = n - (n - x)\)
所以,\(x = n - n - e \times d + 2\)
所以,\(x = n - m\)
所以,\(p + q = m\)
\(\left\{\begin{aligned}p \times q & = & n \\p + q & = &n-e \times d+2 \\\end{aligned}\right.\)
\(\alpha=n-ed+2=p+q\)
\((p-q)^2=p^2-2qp+q^2 \dots \boxed1\)
\((p+q)^2=p^2 + 2qp+q^2 \dots \boxed2\)
\(qp=n\)
\(\boxed 2-4n=\boxed1\)
\(\sqrt{\boxed1}=p-q\)
\(p-q = \sqrt{\alpha ^ 2 - 4n} = \beta\)
\(q = \frac{\alpha + \beta}{2}\)
\(p = \frac{\alpha - \beta}{2}\)
求值
#include<bits/stdc++.h>
#define ll long long
ll k;
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> k;
while(k--){
ll n, e, d, p = 0, q = 0, a, b;
cin >> n >> e >> d;
a = n - e * d + 2;
b = a * a - 4 * n;
ll c = sqrt(b);
if(c * c != b){
cout << "NO\n";
continue;
}
b = c;
q = (a + b) / 2;
p = (a - b) / 2;
if(p * q != n || (p - 1) * (q - 1) + 1 != e * d){
cout << "NO\n";
continue;
}
cout << p << ' ' << q << '\n';
}
return 0;
}
标签:ll,sqrt,times,beta,alpha,随笔,CSP,赛前
From: https://www.cnblogs.com/SZXcoco/p/18502230/2024CSP-J2suibi