Last active
January 8, 2016 00:31
-
-
Save MagallanesFito/066cbef1ee381b898f50 to your computer and use it in GitHub Desktop.
Solucion K-Ceros. Busqueda binaria
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
| #include<iostream> | |
| using namespace std; | |
| #define op_io ios_base::sync_with_stdio(0);cin.tie(0); | |
| typedef unsigned long long int ULL; | |
| ULL ceros(ULL n){ | |
| if(n<=1){ | |
| return 0; | |
| } | |
| return n/5 + ceros(n/5); | |
| } | |
| ULL busqBinaria(ULL izq,ULL der, ULL m){ | |
| if(izq > der) return izq; | |
| ULL p = (izq+der)/2; | |
| if(ceros(p)>=m) | |
| return busqBinaria(izq,p-1,m); | |
| else if(ceros(p) <= m) | |
| return busqBinaria(p+1,der,m); | |
| return -1; | |
| } | |
| ULL buscar(ULL m){ | |
| return busqBinaria(0,5L*m,m); | |
| } | |
| int main(){ | |
| op_io | |
| ULL m; | |
| cin>>m; | |
| cout << buscar(m); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment