Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
meiyong/* ******************************** Author : danmu Created Time : 2016年03月18日 星期五 17时07分21秒 File Name : pku1019.cpp Vim Command copy -> yy paste -> p P del this line -> dd Ctrl-Z -> u U copy into system -> "+y ******************************** */ #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <iomanip> #include <string> #include <vector> #include <cstdio> #include <stack> #include <queue> #include <cmath> #include <list> #include <map> #include <set> #define ULL unsigned long long #define PI 3.1415926535 #define INF 0x3f3f3f3f #define LL long long #define eps 1e-8 using namespace std; LL digit[50000],sum[50000]; void init() { sum[0]=digit[0]=0; for(int i=1;i<50000;++i) { int tmp1=10,tmp2=1; if(i/tmp1) { ++tmp2; tmp1*=10; } digit[i]=digit[i-1]+tmp2; sum[i]=sum[i-1]+digit[i]; if(sum[i]>=2147483647) break; } printf("%d %lld\n",i,sum[i]); } int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); int t; init(); scanf("%d",&t); while(t--) { LL l=0,r=2147483647,i; scanf("%lld",&i); while(r-l>1) { LL mid=(l+r)/2; if(mid*(mid+1)/2<=i) l=mid; else r=mid; } if(i-l*(l+1)/2) printf("%lld\n",i-l*(l+1)/2); else printf("%lld\n",l); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator