Skip to content

Commit

Permalink
Introduction to Linear recurrences and Matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanashii76 authored Feb 25, 2024
1 parent 4101429 commit 0f26e3b
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
38 changes: 38 additions & 0 deletions theory/linear_recurrences_matrix_expo/binaryExponetiation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <iostream>

int binaryPower(int a, int b) {

if (a == 0)
return 0;

int res = 1;
while(b) {
if(b&1)
res *= a;
a*=a;
b = b>>1;
}

return res;

}


int main(void) {

std::cout << binaryPower(2,10) << std::endl;


}












44 changes: 44 additions & 0 deletions theory/linear_recurrences_matrix_expo/enxugando_gelo_no_sol.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <iostream>

typedef long long ll;

const int mod = 1e9+7;

ll mfac(int i) {

int m = i+2;
int ans = 1;

for(int i = 0; i < 3; ++i) {
m %= mod;
ans *= m-i;
ans %= mod;
}

return ans;

}

ll solve(int n) {

int ans = 0;

while(n > 0) {
ans += mfac(n);
n--;
}

return ans;
}


int32_t main(void) {

int n;
std::cin >> n;
std::cout << solve(n) << std::endl;


}


Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <iostream>

#define int long long int

// Constant isn't necessary
const int mod = 1e9 + 7;

int binaryExponentation(int a, int b) {

if (a == 0)
return 0;

int ans = 1;
while(b) {
if(b&1)
ans *= a, ans %= mod;
a*=a;
a %= mod;
b = b>>1;
}

return ans;

}

int32_t main ( void ){

std::cout << binaryExponentation(10,20) << std::endl;

}


0 comments on commit 0f26e3b

Please sign in to comment.