本来是找二分查找的题目的,找到一个这个题目,,,开始一直在往二分上想.
最后不得不放弃,,才发现,原来是个数学规律题目
贴出代码大家看看吧:
写的挺简单的...
#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; }