Unfortunately we were unable to fully decode your file, as it is not encoded in UTF-8. You can try to decode it yourself by downloading it here.
  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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 #include #include using namespace std; long long modulos[20]; long long cycles[20]; long long suffix[20]; // MNO�ENIE LICZB <10^18 MODULO 10^18 long long multiply(long long a, long long b){ // mno�ymy po kolei b%10^n * n-ta cyfra a od ko�ca. // W ten spos�b maksymalnym mno�eniem b�dzie 999'999'999'999'999'999 * 9 // TA-DAAA unsigned long long main_mod = modulos[18]; unsigned long long b_mod = main_mod; unsigned long long current_mult = 1ULL; unsigned long long _first; unsigned long long result = 0ULL; while(a > 0){ _first = a % 10ULL; a /= 10ULL; _first *= current_mult; current_mult *= 10ULL; b %= b_mod; b_mod /= 10ULL; result += _first * b; result %= main_mod; } return (long long)result; } struct fib{ long long matr[2][2]; long long num; fib(){} fib(long long f2, long long f1, long long fn, long long num) : num(num) { matr[0][0] = f2; matr[0][1] = f1; matr[1][0] = f1; matr[1][1] = fn; } long long value() const{ // returns num-th fibonacci number. return matr[1][0]; } void mult(fib& b){ // mno�enie macierzy przez macierz long long temp1 = multiply(matr[0][0], b.matr[0][0]) + multiply(matr[0][1], b.matr[1][0]); long long temp2 = multiply(matr[0][0], b.matr[0][1]) + multiply(matr[0][1], b.matr[1][1]); temp1 %= modulos[18]; temp2 %= modulos[18]; matr[0][0] = temp1; matr[0][1] = temp2; matr[1][0] = temp2; matr[1][1] = (temp1 + temp2) % modulos[18]; num += b.num; num %= (modulos[18] * 4LL); } }; long long n, k, result, nlength; // matrix used to go cycle[i] fibonnaci numbers ahead fib cycle_matrix[20]; void check(fib number, int length){ //cout << "Checking " << number.num << ": " << number.value() << " at length " << length << " for " << n << endl; // number - number we are checking // length - current length of suffix if(length == nlength){ if(number.value() % modulos[length] == n){ // if the number matches, that's it. result = number.num; result += cycles[18]; cout << result << endl; exit(0); } }else{ for(int i = 0; i <= 9; ++i){ if(number.value() % modulos[length] == n % modulos[length]){ check(number, length + 1); // matches, go deeper } number.mult(cycle_matrix[length]); } } } void makecyclemtx(){ cycle_matrix[0] = fib(0LL, 1LL, 1LL, 1LL); cycle_matrix[1] = fib(956722026041LL, 1548008755920LL, 2504730781961LL, 60LL); cycle_matrix[2] = fib(212767467264610201LL, 96499764990979600LL, 309267232255589801LL, 300LL); cycle_matrix[3] = fib(827073452325051001LL, 187122583354898000LL, 14196035679949001LL, 1500LL); cycle_matrix[4] = fib(245798558475510001LL, 655976683548980000LL, 901775242024490001LL, 15000LL); cycle_matrix[5] = fib(98381607255100001LL, 810616835489800000LL, 908998442744900001LL, 150000LL); cycle_matrix[6] = fib(890918322551000001LL, 956168354898000000LL, 847086677449000001LL, 1500000LL); cycle_matrix[7] = fib(119408225510000001LL, 561683548980000000LL, 681091774490000001LL, 15000000LL); cycle_matrix[8] = fib(216582255100000001LL, 616835489800000000LL, 833417744900000001LL, 150000000LL); cycle_matrix[9] = fib(415822551000000001LL, 168354898000000000LL, 584177449000000001LL, 1500000000LL); cycle_matrix[10] = fib(158225510000000001LL, 683548980000000000LL, 841774490000000001LL, 15000000000LL); cycle_matrix[11] = fib(582255100000000001LL, 835489800000000000LL, 417744900000000001LL, 150000000000LL); cycle_matrix[12] = fib(822551000000000001LL, 354898000000000000LL, 177449000000000001LL, 1500000000000LL); cycle_matrix[13] = fib(225510000000000001LL, 548980000000000000LL, 774490000000000001LL, 15000000000000LL); cycle_matrix[14] = fib(255100000000000001LL, 489800000000000000LL, 744900000000000001LL, 150000000000000LL); cycle_matrix[15] = fib(551000000000000001LL, 898000000000000000LL, 449000000000000001LL, 1500000000000000LL); cycle_matrix[16] = fib(510000000000000001LL, 980000000000000000LL, 490000000000000001LL, 15000000000000000LL); cycle_matrix[17] = fib(100000000000000001LL, 800000000000000000LL, 900000000000000001LL, 150000000000000000LL); cycle_matrix[18] = fib(1LL, 0LL, 1LL, 1500000000000000000LL); } string s; int main(){ cin >> s; nlength = s.length(); long long tenpower = 1; for(int i = nlength - 1; i >= 0; --i){ n += (long long)(s[i] - 48) * tenpower; tenpower *= 10LL; } modulos[0] = 1LL; for(int i = 1; i < 19; ++i){ modulos[i] = modulos[i - 1] * 10LL; suffix[i] = n % modulos[i]; } cycles[0] = 1LL; cycles[1] = 60LL; cycles[2] = 300LL; cycles[3] = 1500LL; for(int i = 4; i < 19; ++i){ cycles[i] = cycles[i - 1] * 10LL; } makecyclemtx(); // ZNAJDUJEMY KO�C�WKI 6-CYFROWE BRUTEM I PUSZCZAMY OD NICH MAGICZNEGO DFS-A result = -1LL; long long first6 = n % modulos[6]; long long f2 = 0LL; long long f1 = 1LL; long long fnm6 = 0LL; if(nlength <= 6){ for(long long i = 2LL; i < cycles[6]; ++i){ long long fn = (f1 + f2) % modulos[nlength]; f2 = f1; f1 = fn; if(fn == first6){ result = i; break; } } }else{ // CHECK 0/1 HERE JUST IN CASE? // [will see after testing] // maybe multiplied by 1.5 * 10^18 to get the same results mod 10^18 // fix: +3 should do the trick. I think. for(long long i = 2LL; i < cycles[6] + 3; ++i){ long long fn = (f1 + f2) % modulos[18]; f2 = f1; f1 = fn; fnm6 = fn % modulos[6]; if(fnm6 == first6){ // PUSZCZAMY DFS fib newfib(f2, f1, fn, i); check(newfib, 6); } } } if(result == -1LL){ cout << "NIE" << endl; }else{ result += cycles[18]; cout << result << endl; } return 0; }