Sort by

recency

|

11 Discussions

|

  • + 0 comments

    Amazing expereince this was, i am really happy to tell you about the nicherangereview , this is a blog which has solution to oyur every problem of daily life.

  • + 0 comments

    really don't know, why this is rated hard or is in number theory - boils downs to simple dp.

    import heapq as hq
    from collections import defaultdict
    import bisect as bs
    
    DMAX = 18
    
    work = [(1,i) for i in range(10)]
    # strange = defaultdict(set)
    strange = set()
    hq.heapify(work)
    
    while work:
        d,n = hq.heappop(work)
        if d>DMAX: break
        # strange[d].add(n)
        strange.add(n)
        for k in range(max(2,d),DMAX+1): # exclude d=1 and n=0
            if len(str(n*k)) == k:
                hq.heappush(work,(k,n*k))
    
    strange = sorted(strange)
    
    def solve(a,b):
        return bs.bisect_right(strange,b) - bs.bisect_left(strange,a)
    
  • + 0 comments

    My recursive solution to this problem---

    #include<bits/stdc++.h>
    #define ll long long
    #define ull unsigned long long
    #define mod 1000000007
    using namespace std;
    ull binpow(ull x,ull y)/* (x^y)%p in O(log y) */{ull res=1;while (y > 0){if(y&1)res=(res*x);y = y>>1;x=(x*x);}return res;}
    ll binpowmod(ll x,ll y,ll p)/* (x^y)%p in O(log y) */{ull res=1;x=x%p;while (y > 0){if(y&1)res=(res*x)%p;y = y>>1;x=(x*x)%p;}return res;}
    ll mod_inverse(ll n,ll p)/* Returns n^(-1) mod p */{return binpowmod(n,p-2,p);}
    int gcd(int x,int y)
    {
        if(y==0)
            return x;
        return gcd(y,x%y);
    }
    bool comp(pair<int,int> x,pair<int,int> y)
    {
        return x.first<y.first;
    }
    bool comp_pairs_by_s(pair<ll,ll> &x ,pair<ll,ll> &y)
    {
        return x.second<y.second;
    }
    bool isPowerOfTwo (ll x)  
    {  
        /* First x in the below expression is for the case when x is 0 */
        return x && (!(x&(x-1)));  
    }
    
    class cmp      //comparator for priority_queue 
    {               //declaration: priority_queue<int,vector<int>,cmp>
    public:         
        bool operator()(pair<int,int> A,pair<int,int> B)
        {
            if(abs(A.first-A.second)==abs(B.first-B.second))
                return A.first>B.first;
            return abs(A.first-A.second)<abs(B.first-B.second);
        }
    };
    int prime[10005]={0};
    void sieve(void)
    {
     int i,j;
     for(i=0;i<10005;i++)
            prime[i]=1;
     prime[0]=0,prime[1]=0;
     for(i=2;i<=sqrt(10005);i++){
         if(prime[i]){
             for(j=i*i;j<10005;j+=i){
                 prime[j]=0;
             }
         }
     }
        
    }
    void swap(ll &x,ll &y){
        int temp=x;
        x=y;
        y=temp;
    }
      
    unsigned int onesComplement(unsigned int n) 
    { 
       // Find number of bits in the given integer 
       int number_of_bits = floor(log2(n))+1; 
      
       // XOR the given integer with poe(2,  
       // number_of_bits-1 and print the result  
       return ((1 << number_of_bits) - 1) ^ n; 
    }
    
    ll cnt(ull limit,ull num=1,ull len=1){
        if(limit<=9)
            return limit+1;
        if(num>limit)
            return -1;
        if(num>=binpow(10,len) )
            return 0;
        if(num<binpow(10,len-1))
            return -1;
        if(len==1){
            ll ans=5;
            for(ll i=5;i<=9;++i)
                ans+=1+max(0LL,cnt(limit,i*(len+1),len+1));
            return ans;
        }
        ll ans=1;
        ll i=0;
        while(1){
            ll c=cnt(limit,num*(len+i),len+i);
            if(c==-1) break;
            ans+=c;
            i++;
        }
        return ans;
    }
    
    void solve()
    {   
        ull l,r;
        cin>>l>>r;
        cout<<cnt(r)-(l==0?0:cnt(l-1));
        cout<<'\n';  
    }
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int t;
        cin>>t;
        while(t--)
            solve();
    }   
    
  • + 0 comments

    My simple approach

    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #define leadinz zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
    using namespace __gnu_pbds;
    using namespace std;
    typedef unsigned long long ll;
    int len(unsigned long long n)
    {
        string s=to_string(n);
        return s.size();
    }
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        queue<ll> q;
        vector<ll>ans;
        int T;
        ans.push_back(0);
        for (int i=1;i<10;i++) q.push(i);
        while(!q.empty()){
            ll x = q.front();
            q.pop();
            ans.push_back(x);
            for (int i=len(x);i<=18;i++)
                if (i-1 && len(x * i) == i)
                    q.push(x * i);
        }
        sort(ans.begin(),ans.end());
        cin >> T;
        while(T--){
            ll L,R;
            cin >> L >> R;
            int x = count_if(ans.begin(),ans.end(),[L](ll i){return i<L;});
            int y = count_if(ans.begin(),ans.end(),[R](ll i){return i<=R;});
            if(x!=0)cout << y-x<<endl;
            else cout<<y<<endl;
        }
    }
    
  • + 2 comments
    static boolean isStrange(long x){
            long length = String.valueOf(x).length();
            if (length == 1)    
                    return true;
            if ((x%length == 0) && isStrange(x/length))    
                    return true;
            return false;
    }
    
    static int solve(long l, long r) {
            int count = 0;
            for (long i = l; i<=r; i++) 
                    if (isStrange(i))   
                            count++;
            return count;
    }