1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef vector<int> ivec;
ivec number;
//this is just to output the vector, to see the number in the console
ostream &operator << (ostream &stream, ivec &obj)
{
for (unsigned int i = 0; i < (int)obj.size(); i++)
{
stream << obj[i] << " ";
}
return stream;
}
int divide(vector<int> number, int divisor, vector<int> origNum)
{
vector<int> remain;
int sumRemainder = 0;
for (int i = 0; i < number.size(); i++)
{
long long sumDigit = number[i];
if (divisor > sumDigit)
{
for (int j = 0; ; j++)
{
if (number[i] == 0)
sumDigit += pow(10, j);
else
sumDigit += (pow(10, j) * (number[j]));
if (sumDigit > divisor)
break;
if (j > i)
{
cout << "Sorry can't divide this number." <<endl;
break;
}
}
}
int counter;
for (int k = 0; ; k++)
{
divisor *= k;
if (divisor > sumDigit)
break;
counter++;
}
sumDigit -= divisor;
remain.push_back(sumDigit);
if (sumDigit == 0 || divisor > sumDigit)
remain.push_back(number[i+1]);
divide(remain, divisor, number);
}
for (int l = 0; ; l++)
{
if (number[l] == 0)
sumRemainder += pow(10, l);
else
sumRemainder += pow(10, l) * (number[l]);
}
return sumRemainder;
}
int main(int argc, const char * argv[])
{
srand(time(NULL));
for(int i = 1; i <= 617; i++)
{
number.push_back(rand() % 10);
}
cout << number <<endl;
int remainder = divide(number, 123, number);
//I just chose a random number to divide
return 0;
}
|