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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - Jeff

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

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

#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;
}