HTML & JS
#include<bits/stdc++.h>
using namespace std;
int t,k; 
#define int long long
#define p push 
#define pb push_back
#define pp pair<int,int>
#define mod 1000000007
#define ffd(i,n,m) for(int i=n;i<m;i++)
#define vi  vector<int>
#define vvi  vector<vector<int>>
#define pq priority_queue
#define peak(a,i)    ( a[i-1]<a[i]&&a[i]>a[i+1])
   int dp[2][55][51][51][51];int ans;
   
  int isdp(int flag,vi &a,int idx,int t,int s,int n){
    if(idx==a.size()){
       return (s==t&&t==n&&t>=1);
      }
      if(t>17||s>17||n>17)return 0;
      if(dp[flag][idx][t][s][n]!=-1)return dp[flag][idx][t][s][n];
      int limit=a[idx];if(flag==0)limit=9;int ans=0;
      ffd(i,0,limit+1){
         ans=( ans+ isdp((flag==1&&i==a[idx]),a,idx+1,t+(i==3),s+(i==6),n+(i==9)))%mod;ans=ans%mod;
      }
      return dp[flag][idx][t][s][n]=ans%mod;
  }
  
  int isfun(int n){
      if(n==0)return 0;
      memset(dp,-1,sizeof(dp));
      vi a;
      while(n){
          a.pb(n%10);
          n=n/10;
      }reverse(a.begin(),a.end());
      return isdp(1,a,0,0,0,0)%mod;
  }
 
signed main(){
        ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    // t=1; 
    
        cin>>t;  
    for(int i=1;i<=t;i++,cout<<endl){
        // solve();
        int a,b;cin>>a>>b;
    //  if(a==-1&&b==-1)return 0;
     
    cout<<  isfun(b)-isfun(a-1);
        // cout<< solve();
        // cout<<(solve()==1?"YES":"NO") ;
            } 
 
//  cout<<isfun(13);

}

Generated URL:

Output:

No Output
Report Bug