不知道是不是精度问题,代码交到c++wa,交g++过
总体是很简单的,不断去逼近(y+1-eps)/x
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
using namespace std;
#define INF 1e9
#define maxn
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define mset(x) memset(x,0,sizeof(x))
#define eps 1e-9
double x, y;
int ans;
int main(){
// freopen("a.txt","r",stdin);
// freopen(".out","w",stdout);
while(~scanf("%lf%lf", &x, &y)){
if(x>y){
puts("-1");
continue;
}
ans=x-1;
double tmp = (y+1.0-eps)/x;
double y1 = 1.0;
rep(x1,1,(int)x){
int add = (double)x1 * tmp - y1;
y1 += add;
y1 = y1 * (double)(x1+1) / (double)x1;
ans += add;
}
printf("%d\n", ans);
}
return 0;
}