//============================================================================
// Name : FibonacciNaUbogo.cpp
// Author : Tytus Bierwiaczonek
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
int main()
{
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
const int size = 19;
uint64_t a = 0, b = 1, i, n, mod = 1, mod2, counter = 0, suffix;
char input[size];
cin >> input;
n = strlen(input);
for (i = 0; i < n; ++i)
{
mod *= 10;
}
mod2 = mod * mod;
suffix = atoi(input);
while (counter++ < mod2)
{
if (1 == counter % 2)
{
// cout << "a " << a << endl;
if (suffix == a % mod)
{
cout << counter - 1;
return 0;
}
a = (b + a) % mod;
}
else
{
// cout << "b " << b << endl;
if (suffix == b % mod)
{
cout << counter - 1;
return 0;
}
b = (b + a) % mod;
}
}
cout << "NIE";
return 0;
}
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | //============================================================================ // Name : FibonacciNaUbogo.cpp // Author : Tytus Bierwiaczonek // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <stdint.h> #include <string.h> #include <stdlib.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); const int size = 19; uint64_t a = 0, b = 1, i, n, mod = 1, mod2, counter = 0, suffix; char input[size]; cin >> input; n = strlen(input); for (i = 0; i < n; ++i) { mod *= 10; } mod2 = mod * mod; suffix = atoi(input); while (counter++ < mod2) { if (1 == counter % 2) { // cout << "a " << a << endl; if (suffix == a % mod) { cout << counter - 1; return 0; } a = (b + a) % mod; } else { // cout << "b " << b << endl; if (suffix == b % mod) { cout << counter - 1; return 0; } b = (b + a) % mod; } } cout << "NIE"; return 0; } |
English