SlideShare a Scribd company logo
1 of 5
Download to read offline
FIBONACCI NUMBERS IN
MODULO N
NOTICING A CYCLE
• First we look at the last digit of each number in the Fibonacci numbers (Modulo 10) :
n a(n)
0 0
1 1
2 1
3 2
4 3
5 5
6 8
7 3
8 1
9 4
10 5
n a(n)
11 9
12 4
13 3
14 7
15 0
16 7
17 7
18 4
19 1
20 5
21 6
n a(n)
49 9
50 5
51 4
52 9
53 3
54 2
55 5
56 7
57 2
58 9
59 1
n a(n)
60 0
61 1
62 1
63 2
64 3
65 5
66 8
67 3
68 1
69 4
70 5
PISANO PERIOD
• Fibonacci numbers:
• F(n)= F(n-1) + F(n-2)
• with seed values F(0)=0, F(1)=1
• Fibonacci numbers modulo n will always give a repeating sequence
• The period of this sequence is called a Pisano Period
• The nth Pisano period = π(n)
• Fibonacci numbers modulo 2:
• π(n) = 3
• Cycle = 011
• Sequence = 011011011011011011011011011…
• Fibonacci numbers modulo 3:
• π(n) = 8
• Cycle = 01120221
• Sequence =011202210112022101120221…
PROOF
• Let k and n be non-negative numbers, and let r = k mod n
• What is the range of r? R = { 0, 1, 2, … n-1} , |R| = n
• Each Fibonacci number is the sum of a pair numbers ( F(n-1), F(n-2) )
• In modulo n, each Fibonacci number is the sum of a pair of numbers ( F(n-1) mod n, F(n-2)
mod n )
• Is the number of pairs finite? How many possible pairs are there?
• If a + b = c and a and b each have a finite range it follows that c will also have a finite range
• Therefore Fibonacci numbers in modulo n will eventually be the sum of a pair of
numbers that have already been seen earlier in the series, this will conclude the cycle
and the sequence will repeat from that point on
main ()
{
int n, m, temp, f0= 0, f1= 1;
for (int k = 0; k < 10; k++);
{
cout << "Enter how many terms of the series to display:" << endl;
cin >> n;
cout << "Enter a value for m for the series F mod m:" << endl;
cin >> m;
cout << "The series F mod " << m << " is : " << endl;
for ( int i =0; i < n; i++)
{
if (i <= 1)
temp = i;
else
{
// f0 = f0 % m;
// f1 = f1 % m;
temp = f0 + f1;
temp = temp % m;
f0=f1;
f1=temp;
}
cout << i << " " << temp << endl;
}
}
return 0;
}

More Related Content

What's hot

Factoring quadratics ex 2
Factoring quadratics ex 2Factoring quadratics ex 2
Factoring quadratics ex 2Esteban Parra
 
Comparto trabajo en_clase_contigo
Comparto trabajo en_clase_contigoComparto trabajo en_clase_contigo
Comparto trabajo en_clase_contigoAlejandraCadena10
 
Best forex system trading
Best forex system tradingBest forex system trading
Best forex system tradingHoang Anh Viet
 
Best forex trading system
Best forex trading systemBest forex trading system
Best forex trading systemHoang Anh Viet
 
C++ program: Numbers .cpp
C++ program: Numbers .cppC++ program: Numbers .cpp
C++ program: Numbers .cppKhalid Waleed
 
CBNST PPT, Floating point arithmetic,Normalization
CBNST PPT, Floating point arithmetic,NormalizationCBNST PPT, Floating point arithmetic,Normalization
CBNST PPT, Floating point arithmetic,NormalizationAmberSinghal1
 
Documento General de Diseño V 1.0
Documento General de Diseño V 1.0Documento General de Diseño V 1.0
Documento General de Diseño V 1.0Andres Narvaez
 
4 2 lesson - Graphing in Standard Form
4 2 lesson - Graphing in Standard Form4 2 lesson - Graphing in Standard Form
4 2 lesson - Graphing in Standard Formsahutchins74
 
เขียนโปรแกรมภาษา C: คำสั่ง switch
เขียนโปรแกรมภาษา C: คำสั่ง switchเขียนโปรแกรมภาษา C: คำสั่ง switch
เขียนโปรแกรมภาษา C: คำสั่ง switchWarawut
 
digital logic circuits, digital component
digital logic circuits, digital componentdigital logic circuits, digital component
digital logic circuits, digital componentRai University
 

What's hot (20)

Presentación1
Presentación1Presentación1
Presentación1
 
Iwb Training
Iwb TrainingIwb Training
Iwb Training
 
Assembly language 2
Assembly language 2Assembly language 2
Assembly language 2
 
Factoring quadratics ex 2
Factoring quadratics ex 2Factoring quadratics ex 2
Factoring quadratics ex 2
 
Comparto trabajo en_clase_contigo
Comparto trabajo en_clase_contigoComparto trabajo en_clase_contigo
Comparto trabajo en_clase_contigo
 
Best forex system trading
Best forex system tradingBest forex system trading
Best forex system trading
 
Best forex trading system
Best forex trading systemBest forex trading system
Best forex trading system
 
Ch 10 Review #1
Ch 10 Review #1Ch 10 Review #1
Ch 10 Review #1
 
C++ program: Numbers .cpp
C++ program: Numbers .cppC++ program: Numbers .cpp
C++ program: Numbers .cpp
 
Ppt Prog Fox
Ppt Prog FoxPpt Prog Fox
Ppt Prog Fox
 
Ppt Prog Fox
Ppt Prog FoxPpt Prog Fox
Ppt Prog Fox
 
CBNST PPT, Floating point arithmetic,Normalization
CBNST PPT, Floating point arithmetic,NormalizationCBNST PPT, Floating point arithmetic,Normalization
CBNST PPT, Floating point arithmetic,Normalization
 
Documento General de Diseño V 1.0
Documento General de Diseño V 1.0Documento General de Diseño V 1.0
Documento General de Diseño V 1.0
 
4 2 lesson - Graphing in Standard Form
4 2 lesson - Graphing in Standard Form4 2 lesson - Graphing in Standard Form
4 2 lesson - Graphing in Standard Form
 
Polar plots with R
Polar plots with RPolar plots with R
Polar plots with R
 
PROYECTO PEDRO
PROYECTO PEDROPROYECTO PEDRO
PROYECTO PEDRO
 
เขียนโปรแกรมภาษา C: คำสั่ง switch
เขียนโปรแกรมภาษา C: คำสั่ง switchเขียนโปรแกรมภาษา C: คำสั่ง switch
เขียนโปรแกรมภาษา C: คำสั่ง switch
 
digital logic circuits, digital component
digital logic circuits, digital componentdigital logic circuits, digital component
digital logic circuits, digital component
 
Day 1a examples
Day 1a examplesDay 1a examples
Day 1a examples
 
Programming meeting #8
Programming meeting #8Programming meeting #8
Programming meeting #8
 

Similar to Fibonacci Numbers in Modulo N

LECTURE-MMW-02-FIBONACCI-SEQUENCE-SY-2023.pptx
LECTURE-MMW-02-FIBONACCI-SEQUENCE-SY-2023.pptxLECTURE-MMW-02-FIBONACCI-SEQUENCE-SY-2023.pptx
LECTURE-MMW-02-FIBONACCI-SEQUENCE-SY-2023.pptxClareAngelaPalce
 
Syed Ubaid Ali Jafri - Cryptography Techniques
Syed Ubaid Ali Jafri - Cryptography TechniquesSyed Ubaid Ali Jafri - Cryptography Techniques
Syed Ubaid Ali Jafri - Cryptography TechniquesSyed Ubaid Ali Jafri
 
Number System 123.ppt is for binary number system
Number System 123.ppt is for binary number systemNumber System 123.ppt is for binary number system
Number System 123.ppt is for binary number systemdrpreetiwctm
 
UNIT - I.pptx
UNIT - I.pptxUNIT - I.pptx
UNIT - I.pptxamudhak10
 
UNIT - I.pptx
UNIT - I.pptxUNIT - I.pptx
UNIT - I.pptxamudhak10
 
Linear recurrence relations
Linear recurrence relationsLinear recurrence relations
Linear recurrence relationsShaun Wilson
 
Arithmetic sequences (1).ppt
Arithmetic sequences (1).pptArithmetic sequences (1).ppt
Arithmetic sequences (1).pptDeepaIyer32
 
ch3a-binary-numbers.ppt
ch3a-binary-numbers.pptch3a-binary-numbers.ppt
ch3a-binary-numbers.pptRabiaAsif31
 
B sc3 unit 2 number system
B sc3  unit 2 number systemB sc3  unit 2 number system
B sc3 unit 2 number systemMahiboobAliMulla
 
ch3a-binary-numbers.ppt
ch3a-binary-numbers.pptch3a-binary-numbers.ppt
ch3a-binary-numbers.pptssuser52a19e
 
Review on Number Systems: Decimal, Binary, and Hexadecimal
Review on Number Systems: Decimal, Binary, and HexadecimalReview on Number Systems: Decimal, Binary, and Hexadecimal
Review on Number Systems: Decimal, Binary, and HexadecimalUtkirjonUbaydullaev1
 
ch3a-binary-numbers.ppt
ch3a-binary-numbers.pptch3a-binary-numbers.ppt
ch3a-binary-numbers.pptRAJKUMARP63
 
Exploring Tailrec Through Time Until Kotlin.pptx
Exploring Tailrec Through Time Until Kotlin.pptxExploring Tailrec Through Time Until Kotlin.pptx
Exploring Tailrec Through Time Until Kotlin.pptxJoão Esperancinha
 

Similar to Fibonacci Numbers in Modulo N (20)

LECTURE-MMW-02-FIBONACCI-SEQUENCE-SY-2023.pptx
LECTURE-MMW-02-FIBONACCI-SEQUENCE-SY-2023.pptxLECTURE-MMW-02-FIBONACCI-SEQUENCE-SY-2023.pptx
LECTURE-MMW-02-FIBONACCI-SEQUENCE-SY-2023.pptx
 
Syed Ubaid Ali Jafri - Cryptography Techniques
Syed Ubaid Ali Jafri - Cryptography TechniquesSyed Ubaid Ali Jafri - Cryptography Techniques
Syed Ubaid Ali Jafri - Cryptography Techniques
 
Number System 123.ppt is for binary number system
Number System 123.ppt is for binary number systemNumber System 123.ppt is for binary number system
Number System 123.ppt is for binary number system
 
UNIT - I.pptx
UNIT - I.pptxUNIT - I.pptx
UNIT - I.pptx
 
UNIT - I.pptx
UNIT - I.pptxUNIT - I.pptx
UNIT - I.pptx
 
Linear recurrence relations
Linear recurrence relationsLinear recurrence relations
Linear recurrence relations
 
Nss fourier
Nss fourierNss fourier
Nss fourier
 
SPSF03 - Numerical Integrations
SPSF03 - Numerical IntegrationsSPSF03 - Numerical Integrations
SPSF03 - Numerical Integrations
 
Arithmetic sequences (1).ppt
Arithmetic sequences (1).pptArithmetic sequences (1).ppt
Arithmetic sequences (1).ppt
 
S3 pn
S3 pnS3 pn
S3 pn
 
3rd Semester Computer Science and Engineering (ACU) Question papers
3rd Semester Computer Science and Engineering  (ACU) Question papers3rd Semester Computer Science and Engineering  (ACU) Question papers
3rd Semester Computer Science and Engineering (ACU) Question papers
 
ch3a-binary-numbers.ppt
ch3a-binary-numbers.pptch3a-binary-numbers.ppt
ch3a-binary-numbers.ppt
 
B sc3 unit 2 number system
B sc3  unit 2 number systemB sc3  unit 2 number system
B sc3 unit 2 number system
 
Fibonacci using matlab
Fibonacci using matlabFibonacci using matlab
Fibonacci using matlab
 
ch3a-binary-numbers.ppt
ch3a-binary-numbers.pptch3a-binary-numbers.ppt
ch3a-binary-numbers.ppt
 
ch3a-binary-numbers.ppt
ch3a-binary-numbers.pptch3a-binary-numbers.ppt
ch3a-binary-numbers.ppt
 
binary-numbers.ppt
binary-numbers.pptbinary-numbers.ppt
binary-numbers.ppt
 
Review on Number Systems: Decimal, Binary, and Hexadecimal
Review on Number Systems: Decimal, Binary, and HexadecimalReview on Number Systems: Decimal, Binary, and Hexadecimal
Review on Number Systems: Decimal, Binary, and Hexadecimal
 
ch3a-binary-numbers.ppt
ch3a-binary-numbers.pptch3a-binary-numbers.ppt
ch3a-binary-numbers.ppt
 
Exploring Tailrec Through Time Until Kotlin.pptx
Exploring Tailrec Through Time Until Kotlin.pptxExploring Tailrec Through Time Until Kotlin.pptx
Exploring Tailrec Through Time Until Kotlin.pptx
 

Recently uploaded

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Fibonacci Numbers in Modulo N

  • 2. NOTICING A CYCLE • First we look at the last digit of each number in the Fibonacci numbers (Modulo 10) : n a(n) 0 0 1 1 2 1 3 2 4 3 5 5 6 8 7 3 8 1 9 4 10 5 n a(n) 11 9 12 4 13 3 14 7 15 0 16 7 17 7 18 4 19 1 20 5 21 6 n a(n) 49 9 50 5 51 4 52 9 53 3 54 2 55 5 56 7 57 2 58 9 59 1 n a(n) 60 0 61 1 62 1 63 2 64 3 65 5 66 8 67 3 68 1 69 4 70 5
  • 3. PISANO PERIOD • Fibonacci numbers: • F(n)= F(n-1) + F(n-2) • with seed values F(0)=0, F(1)=1 • Fibonacci numbers modulo n will always give a repeating sequence • The period of this sequence is called a Pisano Period • The nth Pisano period = π(n) • Fibonacci numbers modulo 2: • π(n) = 3 • Cycle = 011 • Sequence = 011011011011011011011011011… • Fibonacci numbers modulo 3: • π(n) = 8 • Cycle = 01120221 • Sequence =011202210112022101120221…
  • 4. PROOF • Let k and n be non-negative numbers, and let r = k mod n • What is the range of r? R = { 0, 1, 2, … n-1} , |R| = n • Each Fibonacci number is the sum of a pair numbers ( F(n-1), F(n-2) ) • In modulo n, each Fibonacci number is the sum of a pair of numbers ( F(n-1) mod n, F(n-2) mod n ) • Is the number of pairs finite? How many possible pairs are there? • If a + b = c and a and b each have a finite range it follows that c will also have a finite range • Therefore Fibonacci numbers in modulo n will eventually be the sum of a pair of numbers that have already been seen earlier in the series, this will conclude the cycle and the sequence will repeat from that point on
  • 5. main () { int n, m, temp, f0= 0, f1= 1; for (int k = 0; k < 10; k++); { cout << "Enter how many terms of the series to display:" << endl; cin >> n; cout << "Enter a value for m for the series F mod m:" << endl; cin >> m; cout << "The series F mod " << m << " is : " << endl; for ( int i =0; i < n; i++) { if (i <= 1) temp = i; else { // f0 = f0 % m; // f1 = f1 % m; temp = f0 + f1; temp = temp % m; f0=f1; f1=temp; } cout << i << " " << temp << endl; } } return 0; }