mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
fix inttypes
This commit is contained in:
parent
4c7685fdf6
commit
c93f3ef35e
@ -7,20 +7,21 @@
|
|||||||
// have already found n/2th or (n+1)/2th fibonacci It is a property of fibonacci
|
// have already found n/2th or (n+1)/2th fibonacci It is a property of fibonacci
|
||||||
// similar to matrix exponentiation.
|
// similar to matrix exponentiation.
|
||||||
|
|
||||||
|
#include <cinttypes>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
const long long MAX = 93;
|
const uint64_t MAX = 93;
|
||||||
|
|
||||||
long long f[MAX] = {0};
|
uint64_t f[MAX] = {0};
|
||||||
|
|
||||||
long long fib(long long n) {
|
uint64_t fib(uint64_t n) {
|
||||||
if (n == 0) return 0;
|
if (n == 0) return 0;
|
||||||
if (n == 1 || n == 2) return (f[n] = 1);
|
if (n == 1 || n == 2) return (f[n] = 1);
|
||||||
|
|
||||||
if (f[n]) return f[n];
|
if (f[n]) return f[n];
|
||||||
|
|
||||||
long long k = (n % 2 != 0) ? (n + 1) / 2 : n / 2;
|
uint64_t k = (n % 2 != 0) ? (n + 1) / 2 : n / 2;
|
||||||
|
|
||||||
f[n] = (n % 2 != 0) ? (fib(k) * fib(k) + fib(k - 1) * fib(k - 1))
|
f[n] = (n % 2 != 0) ? (fib(k) * fib(k) + fib(k - 1) * fib(k - 1))
|
||||||
: (2 * fib(k - 1) + fib(k)) * fib(k);
|
: (2 * fib(k - 1) + fib(k)) * fib(k);
|
||||||
@ -29,7 +30,7 @@ long long fib(long long n) {
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
// Main Function
|
// Main Function
|
||||||
for (long long i = 1; i < 93; i++) {
|
for (uint64_t i = 1; i < 93; i++) {
|
||||||
std::cout << i << " th fibonacci number is " << fib(i) << "\n";
|
std::cout << i << " th fibonacci number is " << fib(i) << "\n";
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user