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

推荐订阅源

T
Tor Project blog
博客园 - 聂微东
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 【当耐特】
G
Google Developers Blog
J
Java Code Geeks
The Cloudflare Blog
Attack and Defense Labs
Attack and Defense Labs
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI
Cisco Talos Blog
Cisco Talos Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
I
Intezer
Jina AI
Jina AI
T
Tenable Blog
P
Palo Alto Networks Blog
Project Zero
Project Zero
D
DataBreaches.Net
Hugging Face - Blog
Hugging Face - Blog
The Hacker News
The Hacker News
F
Full Disclosure
Cloudbric
Cloudbric
量子位
H
Heimdal Security Blog
K
Kaspersky official blog
有赞技术团队
有赞技术团队
罗磊的独立博客
V
Vulnerabilities – Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
阮一峰的网络日志
阮一峰的网络日志
Vercel News
Vercel News
Recent Announcements
Recent Announcements
WordPress大学
WordPress大学
GbyAI
GbyAI
S
SegmentFault 最新的问题
M
MIT News - Artificial intelligence
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
I
InfoQ
Recorded Future
Recorded Future
Security Archives - TechRepublic
Security Archives - TechRepublic
AI
AI
Webroot Blog
Webroot Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
爱范儿
爱范儿
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
The Exploit Database - CXSecurity.com
Apple Machine Learning Research
Apple Machine Learning Research
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hacker News: Front Page
Latest news
Latest news

博客园 - 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;
}