A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/da/dc9/fibonacci__matrix__exponentiation_8cpp.html below:

TheAlgorithms/C++: math/fibonacci_matrix_exponentiation.cpp File Reference

25 {

26

std::vector<uint64_t>

result

(2, 0);

27 std::vector<std::vector<uint64_t>> transition(2,

28 std::vector<uint64_t>(2, 0));

29 std::vector<std::vector<uint64_t>> Identity(2, std::vector<uint64_t>(2, 0));

30 n--;

32 Identity[0][0] = 1;

33 Identity[0][1] = 0;

34 Identity[1][0] = 0;

35 Identity[1][1] = 1;

36

37 transition[0][0] = 0;

38 transition[1][0] = transition[1][1] = transition[0][1] = 1;

39

40 while (n) {

41 if (n % 2) {

42 std::vector<std::vector<uint64_t>> res(2,

43 std::vector<uint64_t>(2, 0));

44 for (int i = 0; i < 2; i++) {

45 for (int j = 0; j < 2; j++) {

46 for

(

int

k = 0;

k

< 2;

k

++) {

47 res[i][j] =

48 (res[i][j] % mod +

49

((Identity[i][

k

] % mod * transition[

k

][j] % mod)) %

50 mod) %

51 mod;

52 }

53 }

54 }

55 for (int i = 0; i < 2; i++) {

56 for (int j = 0; j < 2; j++) {

57 Identity[i][j] = res[i][j];

58 }

59 }

60 n--;

61 } else {

62 std::vector<std::vector<uint64_t>> res1(

63 2, std::vector<uint64_t>(2, 0));

64 for (int i = 0; i < 2; i++) {

65 for (int j = 0; j < 2; j++) {

66 for

(

int

k = 0;

k

< 2;

k

++) {

67 res1[i][j] =

68

(res1[i][j] % mod + ((transition[i][

k

] % mod *

69

transition[

k

][j] % mod)) %

70 mod) %

71 mod;

72 }

73 }

74 }

75 for (int i = 0; i < 2; i++) {

76 for (int j = 0; j < 2; j++) {

77 transition[i][j] = res1[i][j];

78 }

79 }

80 n = n / 2;

81 }

82 }

83 return ((result[0] % mod * Identity[0][0] % mod) % mod +

84 (result[1] % mod * Identity[1][0] % mod) % mod) %

85 mod;

86}

double k(double x)

Another test function.

uint64_t result(uint64_t n)


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4