Light Oj 1138 Trailing Zeroes (III) solution

  Solution in C++: 

///******Bismillahir-Rahmanir-Rahim******///

///AH Tonmoy

///Department of CSE,23rd batch

    ///Islamic University,Bangladesh 

    #include<bits/stdc++.h>
    using namespace std;
    int five(int n)
    {
    int sz=0;
    while(n)
    {
    sz+=n/5;
    n/=5;
    }
    return sz;
    }
    int main()
    {
    int t,i;
    cin>>t;
    for(i=1; i<=t; i++)
    {
    int l=0,r=1000000000,v;
    cin>>v;
    while(l<=r)
    {
    int mid=l+(r-l)/2;
    if(five(mid)>=v)
    r=mid-1;
    else
    l=mid+1;
    }
    if(five(l)==v)
    printf("Case %d: %d\n", i, l);
    else
    printf("Case %d: impossible\n", i);
    }

    }

    1 comment:

    1. https://lightoj.com/problem/crossed-ladders
      ata solve kore de

      ReplyDelete

    Most View Post

    Recent post

    Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

      Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

    Powered by Blogger.