Exemple #1
0
int main(){

    long long int d_min = 100000000;
    long long int l_min = 100000000;
    long long int r_min = 100000000;    
    
    long long int sa;
    long long int wa;    
    
    for (long long int i = 1; i < 10000000000; i++) {
        sa = 3*i + 1;
        wa = (sa + 1) * i + 1;

        if (is_penta(sa) && is_penta(wa)) {
            d_min = min(d_min, sa);
            l_min = penta(i);
            r_min = penta(i+1);
        }
    }
    printf("d_min: %lld\n", d_min);
    printf("l_min: %lld\n", l_min);
    printf("r_min: %lld\n", r_min);    

    
    return 0;
}
Exemple #2
0
/*
 * T(n) = n*(n+1)/2
 * P(m) = m*(3m-1)/2
 * H(k) = k*(2k-1)
 *
 * If T(n) == P(m) == H(k), it is easy to see that k=(n+1)/2
 * So, for all odd n, we have a corresponding H(k) where k = (n+1)/2
 *
 * We now have to find m where T(n) == P(m) and n is odd.
 * One way of doing this is to verify for all T(n), where n is odd, if T(n) is
 * also pentagonal.
 * Given,
 * 	  T(n) = m(3*m - 1)/2
 *   => 2*T(n) = 3m^2 - m
 *   => 3m^2 - m - 2T(n) = 0   
 * 
 * Solving the above quadratic equation for integral m using:
 * m = (-b +/- sqrt(b^2 - 4ac))/2a, where
 * a = 3, b = -1, c = -2T(n), we get the required value of m
 *
 * m = [ -(-1) +/- sqrt((-1)^2 - 4*3*(-2T(n)) ] / 2(3)
 * m = [ 1 + sqrt(1 + 24T(n)) ] / 6
 * We can ignore the second root since it turns out to be a negative number
 */
int
main()
{
	int n;
	uint64_t tn;

	for (n = 3; ;n += 2) {
		tn = T(n);
		if (is_penta(tn)) {
			if (tn == 40755) {
				continue;
			}
			printf("n-%d T(n)-%lu\n", n, tn);
			break;
		}
	}

	return (0);
}
Exemple #3
0
int compare_pentas(int j, int k)
{
        return is_penta(k-j) &&
               is_penta(k+j)  ;
}