Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #include<ext/pb_ds/assoc_container.hpp>
- #include<ext/pb_ds/tree_policy.hpp>
- using namespace __gnu_pbds;
- using namespace std;
- #define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
- #define pb push_back
- #define all(x) (x).begin(),(x).end()
- #define ll long long
- #define ull unsigned long long
- #define ld long double
- #define eps 1e-9
- #define sz(a) (ll)(a).size()
- #define ppc __builtin_popcount
- #define ppcll __builtin_popcountll
- #define endl "\n"
- #define lb lower_bound
- #define ub upper_bound
- #define ordered_set tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
- #define ordered_multiset tree<ll, null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
- const ld PI = acos(-1.0);
- const int MOD = 1e9 +7;
- const ll INF = 1e18;
- // if(abs(a-b)<eps) --> if(a==b)
- // fixed << setprecision(n) -->printing decimal till n
- // hypot(a ,b) --> sqrt(a^2 + b^2)
- void solve(){
- ll n;
- cin>>n;
- //factors of N
- //We can traverse over sum of digit
- auto val_digit =[&](string s){
- ll sum =0;
- for(int i=0;i<sz(s);i++){
- sum += (s[i]-'0');
- }
- return sum;
- };
- ll ans =0;
- for(int len=1;len<=sz(to_string(n));len++){
- //len = length of M
- for(int i=1;i<=9*len;i++){
- if(n%i) continue;
- //sum of digit
- //We have to find number of M that satisfies this
- ll val = n/i;
- ll sum_of_digit = val_digit(to_string(val));
- if(i==sum_of_digit && sz(to_string(val))==len){
- ans++;
- }
- }
- }
- cout<<ans<<endl;
- }
- int main(){
- IO;
- ll t =1;
- cin>>t;
- for(int i=1;i<=t;i++){
- // cout<<"Case #"<<i<<": ";
- solve();
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment