All pastes #1731507 Raw Edit

msrikkanth

public text v1 · immutable
#1731507 ·published 2009-12-30 05:33 UTC
rendered paste body
#include <iostream>int main() {     unsigned int factorial = 10000;     std::cout << "Enter number : ";     std::cin >> factorial;     const unsigned MAXDIGITS = 10000, BASE = 10000;     unsigned indDigits[MAXDIGITS];     indDigits[0] |= 1;     unsigned int counter = 0, oanda = 0, size = 0;     for(int facts = 2; facts <= factorial; facts++) {         for (int index = counter; index <= size; index++){             oanda += facts * indDigits[index];             indDigits[index] = oanda%BASE;             if(index == counter && !(oanda%BASE)) counter++; //Ignores zeroes thus decreasing number of multiplications             oanda /= BASE; //Determines the carry         }         oanda = oanda?(indDigits[++size]=oanda,0):0; //Stores carry if it is not 0 and sets it back to 0 again     }     unsigned sumDigits = 0;     for (int i = 0; i <= size; i++){         for(int j = 1; j <= BASE/10; j*=10)            //Calculates the sum of this particular digit in base B after converting it to decimal            sumDigits += (indDigits[i]/j)%10;     }     std::cout << "Sum of Digits: " << sumDigits << std::endl;}