您的位置:首页 > 其它

UVA - 10025 The ? 1 ? 2 ? ... ? n = k problem

2014-09-21 13:24 399 查看
#include<cstdio>
#include<cmath>

int main() {

	long long test;	
	long long number;
	long long count;
	int mark;

	scanf("%lld\n\n", &test);
	while(test--) {	
	scanf("%lld\n\n", &number);
	
	number = fabs(number);
	
	for(count = 1; ; count++) 
		if((count * count + count ) / 2 >= number)	
			break;	

	while(((count * count + count) / 2 - number) % 2 != 0)
		count++;

/*	if(temp == 1 && count % 2 == 0 && i != test - 1) {
		printf("%d\n\n", count + 1);
		continue;
	}
	if(temp == 1 && count % 2 == 0 && i == test - 1) {
		printf("%d\n", count + 1);
		continue;
	}
	if(temp % 2 == 0)
		mark = 1;
	else
		mark = 0;
	
	if(mark == 1 && i != test - 1)
		printf("%lld\n\n", count);
	if(mark == 0 && i != test - 1)
		printf("%lld\n\n", count + 2);
	if(mark == 1 && i == test - 1)
		printf("%lld\n", count);
	if(mark == 0 && i == test - 1)
		printf("%lld\n", count + 2);
	*/
	if(number== 0)
		printf("3\n");
	else 
		printf("%d\n", count);
	if(test)
		printf("\n");
	}
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: