Project Euler Homework
|
00001 #include <iostream> 00002 using namespace std; 00003 00004 unsigned long pow10(unsigned p) 00005 { 00006 unsigned long product = 1; 00007 for (unsigned k=1;k<=p;k++) { 00008 product*=10; 00009 } 00010 return product; 00011 } 00012 00013 long no_of_integers_of_order(unsigned x) 00014 { 00015 return pow10(x)-pow10(x-1); 00016 } 00017 00018 int d(long k) 00019 { 00020 int i; 00021 long last_complete_series=0; 00022 for (i=1;last_complete_series<k;i++) { 00023 last_complete_series+=i*no_of_integers_of_order(i); 00024 } 00025 00026 i--; 00027 long incomplete_sequence = k- (last_complete_series-i*no_of_integers_of_order(i)); 00028 00029 long quo = incomplete_sequence / i; 00030 long ren = incomplete_sequence-quo*i; 00031 00032 int last_integer = quo+pow10(i-1); 00033 int position = i-ren; 00034 00035 int digit = (last_integer/pow10(position))%10; 00036 //cout << last_integer << '\t' << position << endl; 00037 return digit; 00038 00039 00040 } 00041 00042 int main() 00043 { 00044 unsigned prod=1; 00045 for (long i=10;i<=1000000;i*=10) 00046 prod *= d(i); 00047 cout << prod << endl; 00048 return 0; 00049 }