int main(int argc, char* argv[]) { if(argc != 2) { std::cerr << "usage: " << argv[0] << " <count>\n"; return 0; } const int max = boost::lexical_cast<int>(argv[1]); Factorial factorial; for(int a = 1; a < max; ++a) { for(int b = 1; b < max; ++b) { for(int c = 2; c < max; ++c) { if((a > b) && isDivisible (b, c) && isDivisible (a - b, c) && ((a - b / c) == factorial[(a - b) / c])) { print(a, b, c); } } } } return 0; }
bool isDivisible(int * a, int count, int x1, int x2, int x3) { calls++; if (!count) { return x1 == x2 && x2 == x3; } return isDivisible(a + 1, count - 1, x2, x3, x1 + *a) || isDivisible(a + 1, count - 1, x1, x3, x2 + *a) || isDivisible(a + 1, count - 1, x1, x2, x3 + *a); }
int main(int argc, const char * argv[]) { // Two arguments passed: int height; int fractals; // Creation of the 2D array to hold our Sierpinski Triangle char triangleArray[1000][1000]; // We need 3 arguments passed. If less or more -> error if (argc != 3) { printf("ERROR: Please enter both a height and a fractal level. \n"); } // Check if the fractal is a digit/number else if (!isNumber(argv[2])) { printf("ERROR: Fractal level must be an integer. \n"); } // Check if the height is a digit/number else if (!isNumber(argv[1])) { printf("ERROR: Height must be an integer. \n"); } // Check if the height is divisble by 2^fractal levels as required else if (isDivisible(height, fractals) == 0) { printf("ERROR: Height not divisible by 2^fractal levels. \n"); } // Check if height is at least of 1 else if (height < 1) { printf("ERROR: Height is too small. \n"); } // Max height is 128 else if (height > 128) { printf("ERROR: Height is too large. \n"); } // Proceed to the recursive fractal figure "Sierpinski Triangles" else { // Start by calling the method once, which will, in return, recursively call itself sierpinskiTriangle(height, triangleArray, height-1, height-1, fractals); // We fill the rest of the empty chars with a space " ". fillEmpty(triangleArray); // Final step, priting the 2D array with for loops int j; int i; for (j = height - 1; j >= 0; j--) { for (i = 0; i < (2*height - 1); i++) printf("%c", triangleArray[i][j]); // New line after every y coordinate is done printing printf("\n"); } } return 0; }
int main(void) { std::vector<int> primes; long long tot = 0; for (int p = 2; p < 1000000; ++p) { if (!isDivisible(p, primes)) { primes.push_back(p); tot += p; } } std::cout << tot << std::endl; return 0; }
bool divide(int * a, int n) { int i, sum, max; if (n == 0) { return true; } sum = a[0]; max = a[0]; for (i = 1; i < n; i++) { sum += a[i]; if ( a[i] > max) { max = a[i]; } } if (sum % 3 != 0 || max > sum / 3) { return false; } qsort(a, n, sizeof(*a), compare); return isDivisible(a + 1, n - 1, 0 , 0, *a); }
void test( const int *v, const int size) { if ( isDivisible( v, 2, 2, 3, 4 ) && isDivisible( v, 3, 3, 4, 5 ) && isDivisible( v, 5, 4, 5, 6 ) && isDivisible( v, 7, 5, 6, 7 ) && isDivisible( v, 11, 6, 7, 8 ) && isDivisible( v, 13, 7, 8, 9 ) && isDivisible( v, 17, 8, 9, 10 ) ) { __int64 mult = 1; __int64 n = 0; for (int m = 0; m < size; m++ ) { n += v[size-1-m] * mult; mult *= 10; } llTotal += n; printf( "%lld: %lld\n", n, llTotal ); } }