This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
def is_prime(n): | |
if n < 2: | |
return False | |
ps = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97] | |
def is_spsp(n, a): | |
d, s = n-1, 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
import math | |
def max_prime_factor(n): | |
maxPrime = -1 | |
# We keep dividing n by 2 to get rid of all the even composite factors. | |
while n % 2 == 0: | |
maxPrime = 2 | |
n >>= 1 # equivalent to n //= 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const port = 3000 | |
require('http') | |
.createServer((req, res) => { | |
console.log('url:', req.url) | |
res.end('hello smartcoding') | |
}) | |
.listen(port, (error)=>{ | |
console.log(`server is running on ${port}`) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Loader(props) { | |
if (!props.showLoader) { | |
return null; | |
} | |
return ( | |
<div className="loader"> | |
<WavyLoader black /> | |
<p>{props.message}</p> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Alert(props) { | |
if (!props.showAlert) { | |
return null; | |
} | |
return ( | |
<div className={props.type}> | |
<h4>{props.title}</h4> | |
<p>{props.summary}</p> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def averageOfLevels(self, root): | |
# In case the tree is empty (you never know :P) | |
if root is None: | |
return | |
# Create the queue for BFS and the list of averages | |
queue = [] | |
averages = [] | |
# Enqueue Root and initialize nodes_count_per_level and sum_per_level |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bisect import bisect | |
even_fibs = [2, 8, 34, 144, 610, 2584, 10946, 46368, 196418, 832040, 3524578, 14930352, 63245986, 267914296, 1134903170, | |
4807526976, 20365011074, 86267571272, 365435296162, 1548008755920, 6557470319842, 27777890035288, | |
117669030460994, 498454011879264, 2111485077978050, 8944394323791464, 37889062373143906] | |
t = int(input().strip()) | |
for i in range(t): | |
N = int(input().strip()) | |
print(sum(even_fibs[:bisect(even_fibs, N)])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import sqrt, floor, log | |
from decimal import * | |
context = Context(prec=3000, rounding=ROUND_05UP) | |
setcontext(context) | |
phi = Decimal(1 + Decimal(5).sqrt()) / Decimal(2) | |
psi = Decimal(1 - Decimal(5).sqrt()) / Decimal(2) | |
def reverse_fib(fn): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import sqrt, floor, log | |
phi = (1 + sqrt(5)) / 2 | |
psi = (1 - sqrt(5)) / 2 | |
def reverse_fib(fn): | |
return floor(log((fn * sqrt(5) + sqrt(5 * (fn ** 2) - 4)) / 2, phi)) | |
def get_k(n): | |
return reverse_fib(n) // 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def even_fibonacci_sum(n): | |
fn_2 = 2 #Fn-2 | |
fn_1 = 8 #Fn-1 | |
sum = 10 #first even number Fn-2 + Fn-1 | |
while True : | |
fn = 4 * fn_1 + fn_2 | |
if fn >= n: return sum | |
sum += fn | |
fn_2, fn_1 = fn_1, fn |
NewerOlder