UVA 138 Street Numbers

1282 단어
/*
  :m  ,  n,  [1,n-1] [n+1,m]       ,  10   !
*/
//    
#include <cstdio>
__int64 bsearch(__int64 l, __int64 r)
{
	__int64 left = l;
	__int64 right = r + 1;
	while(left < right )
	{
		__int64 mid = left + (right - left ) / 2;
		__int64 a = (1 + mid - 1) * (mid - 1) / 2;
		__int64 b = (mid + 1 + r) * (r - mid) / 2;
		if( a == b) return mid;
		else if( a > b) right = mid;
		else left = mid + 1;
	}
	return -1;
}
int main()
{
	freopen("f://data.out", "w", stdout);
	const __int64 nMax = 10000000000;
	__int64 i;
	int k = 0;
	for(i = 1; i < nMax; ++ i)
	{
		__int64 p = bsearch(2 , i);
		if(p != -1)
		{
			++ k;
			printf("%10I64d%10I64d
", p, i); } if(k >= 10) break; } return 0; } // #include <cstdio> int main() { printf(" 6 8
"); printf(" 35 49
"); printf(" 204 288
"); printf(" 1189 1681
"); printf(" 6930 9800
"); printf(" 40391 57121
"); printf(" 235416 332928
"); printf(" 1372105 1940449
"); printf(" 7997214 11309768
"); printf(" 46611179 65918161
"); return 0; }

좋은 웹페이지 즐겨찾기