惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Security Latest
Security Latest
T
The Exploit Database - CXSecurity.com
Jina AI
Jina AI
IT之家
IT之家
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
月光博客
月光博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
罗磊的独立博客
C
Cyber Attacks, Cyber Crime and Cyber Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
爱范儿
爱范儿
Cisco Talos Blog
Cisco Talos Blog
V
V2EX
C
CERT Recently Published Vulnerability Notes
Microsoft Azure Blog
Microsoft Azure Blog
Hugging Face - Blog
Hugging Face - Blog
S
Schneier on Security
The Register - Security
The Register - Security
L
Lohrmann on Cybersecurity
博客园 - 聂微东
有赞技术团队
有赞技术团队
Know Your Adversary
Know Your Adversary
V2EX - 技术
V2EX - 技术
大猫的无限游戏
大猫的无限游戏
Project Zero
Project Zero
Simon Willison's Weblog
Simon Willison's Weblog
Last Week in AI
Last Week in AI
博客园 - Franky
D
Docker
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
H
Hacker News: Front Page
MongoDB | Blog
MongoDB | Blog
W
WeLiveSecurity
Vercel News
Vercel News
C
Check Point Blog
N
News | PayPal Newsroom
A
Arctic Wolf
T
Threat Research - Cisco Blogs
F
Full Disclosure
博客园 - 司徒正美
GbyAI
GbyAI
A
About on SuperTechFans
Webroot Blog
Webroot Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
I
InfoQ
Martin Fowler
Martin Fowler
Y
Y Combinator Blog
Latest news
Latest news
Help Net Security
Help Net Security

博客园 - Jeff

4个月 C++ 有限状态机 POJ1035 POJ1007 POJ1005 ONLINE_JUDGE Linux shell定时器 怪异的grep结果 URL2FILE C primer笔记 Vxworks增加system call C语言常用宏定义技巧 分苹果 Socket 为什么选择SMP而不是AMP RTP memory in Vxworks Windriver的项目类型 RTP affinity Symmetric multiprocessing (SMP)
POJ1019
Jeff · 2012-01-17 · via 博客园 - Jeff

2012-01-17 16:41  Jeff  阅读(719)  评论()    收藏  举报

#include "stdio.h"
#include <math.h>
#define SUM_MAX1 45
#define SUM_MAX2 9045
#define SUM_MAX3 1395495
#define SUM_MAX4 189414495
char pre45bits [46]={"112123123412345123456123456712345678123456789"};
unsigned int i,num,position,pos,maxnumber,minnumber,tempvalue1,tempvalue2,current,gap,minnumber2;
unsigned int calc1,calc2,calc3,x,y,z;
unsigned int total=0;
double p=0;
double bits;

void getValue2(unsigned int pos){
     minnumber=9;
     while(minnumber<100){
          tempvalue1=minnumber*minnumber - 8*minnumber+36;
          tempvalue2=(minnumber+1)*(minnumber+1)-8*(minnumber+1)+36;
          if((pos>=tempvalue1) && (pos<tempvalue2)){
              current = tempvalue1;
              gap=pos-tempvalue1;
              break;
          }
          minnumber++;
    }
    if(gap==0){
          printf("%dn",minnumber%10);
       }
    else if(gap <10){
          printf("%dn",gap);
       }
    else{
           calc1 = (gap-9)/2;
           if(((gap-9)%2)==0){
             printf("%dn",(calc1+9)%10);
           }else{
             printf("%dn",(calc1+10)/10);
          }
       }
}

void getValue3(unsigned int pos){
     minnumber=99;
     while(minnumber<1000){
          tempvalue1=minnumber*189-9666+3*(minnumber-98)*(minnumber-99)/2;
          minnumber2=minnumber+1;
          tempvalue2=minnumber2*189-9666+3*(minnumber2-98)*(minnumber2-99)/2;
          if((pos>=tempvalue1) && (pos<tempvalue2)){
              current = tempvalue1;
              gap=pos-tempvalue1;
              break;
          }
          minnumber++;
    }
        if(gap==0){
          printf("%dn",minnumber%10);
       }
       else if(gap <10){
             printf("%dn",gap);
       }else if(gap-9 <=180){
          calc1 = (gap-9)/2;
          if(((gap-9)%2)==0){
             printf("%dn",(calc1+9)%10);
           }else{
             printf("%dn",(calc1+10)/10);
          }
       }else{
          calc2 = (gap-189)/3;
          if(((gap-189)%3)==1){
             printf("%dn",(calc2+100)/100);
          }
          if(((gap-189)%3)==2){
             printf("%dn",((calc2+100)%100)/10);
          }
          if(((gap-189)%3)==0){
             printf("%dn",(calc2+99)%10%10 );
          }
       }
}

void getValue4(unsigned int pos){
     minnumber=999;
     while(minnumber){
          tempvalue1=minnumber*2889-1490616+2*(minnumber-999)*(minnumber-998);
          minnumber2=minnumber+1;
          tempvalue2=minnumber2*2889-1490616+2*(minnumber2-999)*(minnumber2-998);
          if((pos>=tempvalue1) && (pos<tempvalue2)){
              current = tempvalue1;
              gap=pos-tempvalue1;
              break;
          }
          minnumber++;
    }
       if(gap==0){
          printf("%dn",minnumber%10);
       }
       else if(gap <10){
             printf("%dn",gap);
       }else if(gap-9 <=180){
          calc1 = (gap-9)/2;
          if(((gap-9)%2)==0){
             printf("%dn",(calc1+9)%10);
           }else{
             printf("%dn",(calc1+10)/10);
          }
       }else if(gap-189<=2700){
          calc2 = (gap-189)/3;
          if(((gap-189)%3)==1){
             printf("%dn",(calc2+100)/100);
          }
          if(((gap-189)%3)==2){
             printf("%dn",((calc2+100)%100)/10);
          }
          if(((gap-189)%3)==0){
             printf("%dn",(calc2+99)%10 );
          }
       }else{
          calc3= (gap-2889)/4;
          if(((gap-2889)%4)==1){
             printf("%dn",(calc3+1000)/1000);
          }
          if(((gap-2889)%4)==2){
             printf("%dn",(calc3+1000)%1000/100);
          }
          if(((gap-2889)%4)==3){
             printf("%dn",(calc3+1000)%100/10);
          }
          if(((gap-2889)%4)==0){
             printf("%dn",(calc3+99)%10);
          }
       }
}

void getValue5(unsigned int pos){
     minnumber=9999;
     while(minnumber<33000){
           x=minnumber-9999;
           tempvalue1 = 189414495+38889*x + 5*(x+1)*x/2;
           minnumber2 = x+1;
          tempvalue2 = 38889*minnumber2 + 5*(minnumber2+1)*minnumber2/2+189414495;
          if((pos>=tempvalue1) && (pos<tempvalue2)){
              current = tempvalue1;
              gap=pos-tempvalue1;
              break;
          }
          minnumber++;
    }
       if(gap==0){
          printf("%dn",minnumber%10);
       }
       else if(gap <10){
             printf("%dn",gap);
       }else if(gap-9 <=180){
          calc1 = (gap-9)/2;
          if(((gap-9)%2)==0){
             printf("%dn",(calc1+9)%10);
           }else{
             printf("%dn",(calc1+10)/10);
          }
       }else if(gap-189<=2700){
          calc2 = (gap-189)/3;
          if(((gap-189)%3)==1){
             printf("%dn",(calc2+100)/100);
          }
          if(((gap-189)%3)==2){
             printf("%dn",((calc2+100)%100)/10);
          }
          if(((gap-189)%3)==0){
             printf("%dn",(calc2+99)%10 );
          }
       }else if(gap-2889<36000){
          calc3= (gap-2889)/4;
          if(((gap-2889)%4)==1){
             printf("%dn",(calc3+1000)/1000);
          }
          if(((gap-2889)%4)==2){
             printf("%dn",(calc3+1000)%1000/100);
          }
          if(((gap-2889)%4)==3){
             printf("%dn",(calc3+1000)%100/10);
          }
          if(((gap-2889)%4)==0){
             printf("%dn",(calc3+999)%10);
          }
       }
       else{
           calc3= (gap-38889)/5;
          if(((gap-38889)%5)==1){
             printf("%dn",(calc3+10000)/10000);
          }
          if(((gap-38889)%5)==2){
             printf("%dn",(calc3+10000)%10000/1000);
          }
          if(((gap-38889)%5)==3){
             printf("%dn",(calc3+10000)%1000/100);
          }
          if(((gap-38889)%5)==4){
             printf("%dn",(calc3+10000)%100/10);
          }

          if(((gap-38889)%5)==0){
             printf("%dn",(calc3+9999)%10);
          }
       }
}
int main(){
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#else
#endif
scanf("%d",&num);
for(i=0;i<num;i++){
    scanf("%u",&position);
    if(position<=45){
       printf("%cn",pre45bits[position-1]);
    }else if(position<=9045){
        getValue2(position);
    }else if(position<=1395495){
        getValue3(position);
    }else if(position<=189414495){
        getValue4(position);
    }else{
        getValue5(position);
    }

}

#ifndef ONLINE_JUDGE
fclose(stdin);
#else
#endif
return 0;
}