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
| long long euler1(long long N) { | |
| long long i, sum = 0; | |
| for (i = 3; i < N; i++) { | |
| if (i % 3 == 0 || i % 5 == 0) { | |
| sum += i; | |
| } | |
| } | |
| return sum; | |
| } |
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 sum(n, k): | |
| d = n // k | |
| return k * (d * (d+1)) // 2 | |
| def euler1(n): | |
| return sum(n, 3) + sum(n, 5) - sum(n, 15) | |
| t = int(input().strip()) | |
| for i in range(t): | |
| N = int(input().strip()) |
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 = 1 #Fn-2 | |
| fn_1 = 1 #Fn-1 | |
| sum = 0 | |
| while True : | |
| fn = fn_2 + fn_1 #Fn | |
| if fn >= n: return sum | |
| if fn % 2 == 0: sum += fn | |
| fn_2, fn_1 = fn_1, 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
| 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 |
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
| 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 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
| 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
| 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
| function Loader(props) { | |
| if (!props.showLoader) { | |
| return null; | |
| } | |
| return ( | |
| <div className="loader"> | |
| <WavyLoader black /> | |
| <p>{props.message}</p> | |
| </div> |
OlderNewer