Jump to content

User:NorwegianBlue/tetranacci-problem

From Wikipedia, the free encyclopedia
#pragma warning(disable: 4786)
#pragma warning(disable: 4996)

#include <iostream>

int main()
{
	unsigned long two_pow_25 = 33554432;
	unsigned long mask_table[22]; // Position 22 is the last one where a 4 element sequence can begin (22,23,24,25).

	unsigned long mask = 15; // binary 1111.
	for (unsigned i = 0; i < 22; ++i)
	{
		mask_table[i] = mask;
		mask *= 2;
	}

	unsigned long counter = 0;
	for (unsigned long k = 0; k < two_pow_25; ++k)
	{
		bool fail = false;
		for (int i = 0; i < 22; ++i)
		{
			fail = ((k & mask_table[i]) == mask_table[i]);
			if (fail)
			{
				break;
			}
		}
		if (!fail)
		{
			++counter;
		}
	}
	// Yup, counter = 14564533 = a(29)
	std::cout << counter << '\n';
	exit(0);
}