大概就是给你两个数A和B,有且仅有一组n,k满足:
然后输出 和
暴力枚举k即可。
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
#define ll long long
ll A,B,n,k,sq,x,y,ans1,ans2;
ll sqr( ll t , ll k ) {
ll p = 1 ;
while ( k -- ) p *= t ;
return p ;
}
int main() {
cin >> A >> B ;
while ( 1 ) {
if ( A + B == 0 ) break ;
if ( B == 1 ){
cout << "0 " << A << endl ;
cin >> A >> B ;
continue ;
}
for (ll i = 1 ; i <= 31 ; i++ ) {
double h1,h2 ;
h1 = pow( A , (double) 1 / (double) i ) - 1 ;
h2 = pow( B , (double) 1 / (double) i ) ;
if ( fabs( h1 - h2) < 1e-14 ) {
n = (ll) ( h1 + 0.5 ) ;
k = i ;
break ;
}
}
ans1 = sqr( n , k ) / ( n - 1 ) ;
ans2 = 0 ;
for (ll i = 0 ; i <= k ; i ++ )
ans2 += sqr( n + 1 , k - i ) * sqr( n , i ) ;
cout << ans1 << " " << ans2 << endl ;
cin >> A >> B ;
}
return 0;
}