{{ message }}

Instantly share code, notes, and snippets.

Izan Beltran izanbf1803

Created Jan 5, 2019
Find last m non-zero digits of n!
View factorial_info.py
This file contains 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
 # Find last m non-zero digits of n! n, m = map(int, input().split()) cnt = 0 power = 5 while n // power > 0: cnt += n // power power *= 5 print(f"{n}! has {cnt} zeros.")
Last active Jan 5, 2019
Solución del problema "A gas station too far"
View A gas station too far.py
This file contains 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 jutge import read # Cosas del input... def optimize(f, f_extra_args, l, r, y): # Tiempo: O(t(f) log(r-l)) donde t(f) es el coste de calcular f(x) # # Este método maximiza la función f y si hay varios inputs que dan # el valor y encuentra el mínimo {min x | f(x) = y} y se # cumple que la función f es (no estrictamente) creciente, es decir, # que siempre {f(x) >= f(x+1)}. # Si tienes una función decreciente {f(x) <= f(x+1)} puedes convertirla
Last active Jan 1, 2019
View gen_2019.cc
This file contains 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
 #include using namespace std; #define endl '\n' template using V = vector; using pii = pair; const int N = 2019;
Created Dec 31, 2018
Primes class to factorize integers.
View primes.py
This file contains 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
 import sys from math import * def error(err): print("Error:", err) sys.exit(0) def lcm(a, b): return a//gcd(a,b)*b
Created Dec 31, 2018
Draw Pascal's triangle with simple format
View pascal_triangle.cc
This file contains 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
 #include using namespace std; void pascals_triangle(int n) { n = 1 << (n+1); vector> a; a.resize(n); a[0].resize(1); a[0][0] = 1;
Created Dec 5, 2018
Console output color
View colormod.h
This file contains 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
 #include namespace Color { enum Code { FG_RED = 31, FG_GREEN = 32, FG_BLUE = 34, FG_DEFAULT = 39, BG_RED = 41, BG_GREEN = 42,
Created Nov 3, 2018
Reduce memory usage in dataframe.
View reduce_mem_usage.py
This file contains 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
 # Reference: https://www.kaggle.com/gemartin/load-data-reduce-memory-usage def reduce_mem_usage(df): """ iterate through all the columns of a dataframe and modify the data type to reduce memory usage. """ start_mem = df.memory_usage().sum() / 1024**2 print('Memory usage of dataframe is {:.2f} MB'.format(start_mem)) for col in df.columns:
Created Oct 18, 2018
Sample of generating functions implementation using Sympy.
View gen_func_sample.py
This file contains 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
 """ Problem: Cody has 4 types of onions. The number of purple onions can be any non-negative integer. The number of green onions is a multiple of 2. The number of red onions is a multiple of 3. The number of blue onions is a multiple of 5. If Cody has N onions, how many different distributions of colors can there be? """
Last active Jan 15, 2019
Compact recursive implementation of basic Segment Tree.
View SegmentTree.cc
This file contains 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
 template struct SegmentTree { int n; T* t; T zero_val; inline T merge(T a, T b) { return a + b; // MODIFY FOR EACH PROBLEM }
Last active Sep 6, 2018
Compact and fast Iterative Segment Tree basic implementation.
View IterativeSegmentTree.cc
This file contains 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
 // Reference: http://codeforces.com/blog/entry/18051 template struct SegmentTree { int n; T* t; T zero_val; inline T operation(T a, T b) { return max(a, b);