Skip to content

Instantly share code, notes, and snippets.

@jepler
Created July 20, 2024 20:51
Show Gist options
  • Save jepler/f6296a5a63a82446f8146e0a74cdbe7b to your computer and use it in GitHub Desktop.
Save jepler/f6296a5a63a82446f8146e0a74cdbe7b to your computer and use it in GitHub Desktop.
#include <gmpxx.h>
#include <charconv>
#include <string>
#include <iomanip>
#include <iostream>
using namespace std;
int main(int argc, char **argv) {
for(int i=1; i<argc; i++) {
size_t ai;
if (std::from_chars(argv[i], argv[i] + strlen(argv[i]), ai).ec == std::errc{}) {
const mpz_class v = mpz_class::fibonacci(ai);
cout << setw(15) << ai << ": "
<< mpz_sizeinbase(v.get_mpz_t(), 10) << " digits,"
<< mpz_sizeinbase(v.get_mpz_t(), 2) << " bits\n"
;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment