- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define M 1000003
- #define S 1000003
- #define LL long long
- using namespace std;
- int n;
- int BS(int h, int l){
- int p, q, m, f = 0;
- while(h >= l){
- p = h+l;
- if(p&1)p += 5;
- m = p/2;
- q = m;
- if(f == m)return -1;
- f = m;
- int ans = 0;
- while(q > 0){
- ans += q/5;
- q /= 5;
- }
- if(ans == n)return m;
- else if(ans > n)h = m;
- else l = m;
- }
- return -1;
- }
- int main(){
- int t, cs = 0;
- scanf("%d", &t);
- while(t--){
- scanf("%d", &n);
- int high = 5*n;
- int low = 5;
- int a = BS(high, low);
- printf("Case %d: ", ++cs);
- printf((a < 0)?"impossible\n":"%d\n", a);
- }
- return 0;
- }
Friday, March 11, 2016
LightOJ - 1138 - Trailing Zeroes (III)
LightOJ - 1090 - Trailing Zeroes (II)
- /****************##### بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم #####******************
- __________________________________________________________________________
- ###################### Ya-Seen Arafat(ACWizard) #########################
- ###################### UAP-CSE-33B #########################
- *************************************************************************/
- #include <bits/stdc++.h>
- #define M 1000003
- #define S 1000003
- #define LL long long
- using namespace std;
- int find_p(int a, int b){
- int cn = 0;
- while(a > 0){
- cn += (a/b);
- a /= b;
- }
- return cn;
- }
- int find_pr(int a, int b){
- int cn = 0;
- while(!(a%b)){
- cn++;
- a /= b;
- }
- return cn;
- }
- int main(){
- int t, n, r, p, q, c, cs = 0;
- scanf("%d", &t);
- while(t--){
- scanf("%d %d %d %d", &n, &r, &p, &q);
- c = n-r;
- int five_up = 0, five_down = 0, two_up = 0, two_down = 0;
- five_up = find_p(n, 5);
- two_up = find_p(n, 2);
- five_down = find_p(c, 5);
- five_down += find_p(r, 5);
- two_down = find_p(c, 2);
- two_down += find_p(r, 2);
- five_up += (q*find_pr(p, 5));
- two_up += (q*find_pr(p, 2));
- int five, two;
- five = five_up-five_down;
- two = two_up-two_down;
- int ans = min(five, two);
- printf("Case %d: %d\n", ++cs, ans);
- }
- return 0;
- }
Subscribe to:
Posts (Atom)