1183

/*
这个题目的意思就是

找出b的最大取值,然后枚举就可以了。默认b<=c

e.g. 
*/

// include file
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <ctime>

#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <bitset>

#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <list>
#include <functional>

using namespace std;

// typedef
typedef __int64 LL;

// 
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)

#define Z(a,b) ((a)<<(b))
#define Y(a,b) ((a)>>(b))

const double eps = 1e-6;
const double INFf = 1e100;
const int INFi = 1000000000;
const LL INFll = (LL)1<<62;
const double Pi = acos(-1.0);

template<class T> inline T sqr(T a){return a*a;}
template<class T> inline T TMAX(T x,T y)
{
	if(x>y) return x;
	return y;
}
template<class T> inline T TMIN(T x,T y)
{
	if(x<y) return x;
	return y;
}
template<class T> inline T MMAX(T x,T y,T z)
{
	return TMAX(TMAX(x,y),z);
}
template<class T> inline T MMIN(T x,T y,T z)
{
	return TMIN(TMIN(x,y),z);
}
template<class T> inline void SWAP(T &x,T &y)
{
	T t = x;
	x = y;
	y = t;
}


// code begin
LL N;
int main()
{
	read;
	write;
	LL b,c,ans,lit;
	while(scanf("%I64d",&N)!=-1)
	{
		ans = INFi;
		lit = (2*N+(LL)sqrt(4*N*N+4.0) )/2;
		for(b=N+1;b<=lit;b++)
		{
			if( (N*b+1)%(b-N)==0 )
			{
				c = (N*b+1)/(b-N);
				if(b+c<ans)
					ans=b+c;
			}
		}
		printf("%I64d\n",ans);
	}
	return 0;
}

posted @ 2011-04-29 17:37  AC2012  阅读(203)  评论(0编辑  收藏  举报