hdu 1597

 1 #include<stdio.h>
 2 #include<iostream>
 3 #include<math.h>
 4 using namespace std;
 5 typedef __int64 ll;
 6 int main()
 7 {
 8     int t,ans;
 9     scanf("%d",&t);
10     int n;
11     ll locb,loca;
12     while(t--)
13     {
14         scanf("%d",&n);
15         locb = ceil(sqrt(2*(double)n+0.25)-0.5);
16     //    cout<<"locab:"<<locb<<endl;
17         loca = locb*(locb-1)/2;
18     //    cout<<"loca:"<<loca<<endl;
19         n = n - loca;
20     //    cout<<"n:"<<n<<endl;
21         ans = n%9;
22         if(ans==0)
23             printf("%d\n",9);
24         else
25             printf("%d\n",ans);
26     }
27     return 0;
28 }

 

posted @ 2012-11-22 21:48  M_cag  阅读(191)  评论(0编辑  收藏  举报