Register
|
Login
Home
News
Competitions
Practice
How to
Rankings
Calendar
Arena
CodeFu 2010
CodeFu'10 Highlights
Jazoon'10 Highlights
Schedule
Rules
Prizes
Results
Competitions
»
Main CodeFu Competitons
»
CodeFu 2010
»
Results
CodeFu 2010 Results
Final Round Results
Goran's solution for 300: NumberSequence, written in Java, submitted on 09.05.2010 14:14:55
public class NumberSequence { public int findDigit(int N) { if(N==1)return 1; if(N==2)return 1; /* int m=0; int p=9; for(int i=1; i<=5; i++){ m += i*(p*(p+1))/2; System.out.println("i : "+i+ " m: "+m); p *= 10; } */ int start; if(N<=45){//one digit start=1; int n[] = {1,2,3,4,5,6,7,8,9}; int end=0, i, curr=0; while(true){ for(i=0; i<=end; i++){ curr++; if(curr==N) return n[i]; } end++; } } else if(N<=8235){ //two digits start = 46; int t=10; for(int ii=start; ii<=8235; ii+=2){ if(N == ii){ return t/10; } else if(N == ii+1){ return t%10; } t++; } } else if(N<=1224585){ //three digits start=8236; int t=100; for(int ii=start; ii<=8235; ii+=3){ if(N == ii){ return t/100; } else if(N == ii+1){ return (t/10)%10; } else if(N == ii+2){ return t%10; } t++; } } else if(N<=163242585){//four digits start=1224585+1; } else if(N<=1000000000){//five digits start=163242585+1; } //System.out.println(m); return 0; } public static void main(String[] args) { // TODO Auto-generated method stub System.out.println(new NumberSequence().findDigit(46)); } }