Modulo Fibonacci finding Cycle in a vector

I have a vector with modulo fibonacci sequence
this sequence has a cycle of what I think is a random number.
If I take Fibonacci modulo 2 i get:
0, 1, 1, 0, 1, 1, 0
The problem is I dont know how to recognise the cycle.
Please help
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
#include "stdafx.h"
#include <iostream>
#include <vector>

int main()
{
	// Mod stores the Modulo
	char Mod = 0;

	// First check the modulo.
	std::cout << "Which modulo?" << std::endl;
	std::cin >> Mod;

	// Fib stores the numbers and ModFib, the Modulo ones.
	std::vector<unsigned long long> Fib = { 0, 1 };
	std::vector<unsigned int> ModFib = ModFib = { 0, 1 };

	// This will create the fibonnaci number.
	while ((Fib[Fib.size() - 1] + Fib[Fib.size() - 2]) >= Fib[Fib.size() - 1]) 
		Fib.push_back(Fib[Fib.size() - 1] + Fib[Fib.size() - 2]);
	for (unsigned int Count = 2; Count < Fib.size(); Count++) 
		ModFib.push_back(Fib[Count] % Mod);

	// Insert Cycle Finding code:

	// Clear the buffer then when someone presses enter quit.
	std::cin.clear(); 
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
	return 0;
}
Last edited on
What you have just seen is me being very very stupid, I WAS USING A CHAR FOR A START!
also I never realised but all the sequences start with 0 then 1 then another 1, I have hastily written a piece of code that asks if after a zero theres is a one and then another one
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
#include "stdafx.h"
#include <iostream>
#include <vector>

int main()
{
	// Fib are the two fibonnacci numbers, ModFib stores Fib,
	int Mod = 0;

	// First check the modulo.
	std::cout << "Which modulo?" << std::endl;
	std::cin >> Mod;

	// Fib stores the numbers and ModFib, the Modulo ones.
	std::vector<unsigned long long> Fib = { 0, 1 };
	std::vector<unsigned int> ModFib = ModFib;

	// This will create the fibonnaci number.
	while ((Fib[Fib.size() - 1] + Fib[Fib.size() - 2]) >= Fib[Fib.size() - 1]) 
		Fib.push_back(Fib[Fib.size() - 1] + Fib[Fib.size() - 2]);
	// Modulo every fibonnacci number
	for (unsigned int Count = 0; Count < Fib.size(); Count++) 
		ModFib.push_back(Fib[Count] % Mod);

	// This will try and find the sequence
	int Check = 0;
	for (unsigned int Count = 1; Count < ModFib.size() - 3; Count++) {
		if (ModFib[Count] == 0) {
			Check++;
			if (ModFib[Count + 1] == 1) {
				Check++;
				if (ModFib[Count + 2] == 1) {
					Check++;
				if (Check == 3)
					std::cout << Count << std::endl;
					Count = ModFib.size();
				}
				else Check = 0;
			}
			else Check = 0;
		}
		else Check = 0;
	}
	// Clear the buffer then when someone presses enter quit.
	std::cin.clear(); 
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
	return 0;
}


Please tell me anything i could improve (I know I can improve that giant load of nested if's and can anyone find a way of finding the sequence with a more elegant method!
Topic archived. No new replies allowed.