題目大意:
題幹;
基本思路:
二分,等差數列;
代碼如下:
#include<iostream>
#include<iomanip>#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long int ll;
bool judge(ll x,ll ans)
{
if(x*(x+1)/2>=ans) return true;
else return false;
}
int main()
{
int num;
scanf("%d",&num);
while(num--)
{
ll ans;
scanf("%I64d",&ans);
ll left=1,right=200000;
ll mid;
while(right>left)//這裏找一個等差數列的和不小於ans;
{
mid=left+(right-left)/(ll)2;
if(judge(mid,ans))right=mid;
else left=mid+1;
}
ans=ans-(left-1)*(left)/(ll)2;
ll t=ans%(ll)9;
if(t==0)//由於模9,所以9的情況成了0
printf("%lld\n",(ll)9);
else
printf("%lld\n",t);
}
return 0;
}