现在的位置: 首页 > 综合 > 正文

HDU-1597(找规律)

2013年12月24日 ⁄ 综合 ⁄ 共 278字 ⁄ 字号 评论关闭

本来是找二分查找的题目的,找到一个这个题目,,,开始一直在往二分上想.

最后不得不放弃,,才发现,原来是个数学规律题目

贴出代码大家看看吧:

写的挺简单的...

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		int N;
		scanf("%d",&N);
		int i=1;
		while(N>i)
		{
			N-=i;
			i++;
		}
		printf(N%9==0?"9\n":"%d\n",N%9);
	}
	return 0;
}

 

抱歉!评论已关闭.