Snapper_001

Untitled

Dec 21st, 2022
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include<ext/pb_ds/assoc_container.hpp>
  3. #include<ext/pb_ds/tree_policy.hpp>
  4. using namespace __gnu_pbds;
  5. using namespace std;
  6. #define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  7. #define pb push_back
  8. #define all(x) (x).begin(),(x).end()
  9. #define ll long long
  10. #define ull unsigned long long
  11. #define ld long double
  12. #define eps 1e-9
  13. #define sz(a) (ll)(a).size()
  14. #define ppc __builtin_popcount
  15. #define ppcll __builtin_popcountll
  16. #define endl "\n"
  17. #define lb lower_bound
  18. #define ub upper_bound
  19. #define ordered_set tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
  20. #define ordered_multiset tree<ll, null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
  21. const ld PI = acos(-1.0);
  22. const int MOD = 1e9 +7;
  23. const ll INF = 1e18;
  24. // if(abs(a-b)<eps) --> if(a==b)
  25. // fixed << setprecision(n) -->printing decimal till n
  26. // hypot(a ,b) --> sqrt(a^2 + b^2)
  27.  
  28. void solve(){
  29. ll n;
  30. cin>>n;
  31.  
  32. //factors of N
  33. //We can traverse over sum of digit
  34.  
  35. auto val_digit =[&](string s){
  36. ll sum =0;
  37. for(int i=0;i<sz(s);i++){
  38. sum += (s[i]-'0');
  39. }
  40. return sum;
  41. };
  42.  
  43. ll ans =0;
  44.  
  45. for(int len=1;len<=sz(to_string(n));len++){
  46. //len = length of M
  47. for(int i=1;i<=9*len;i++){
  48. if(n%i) continue;
  49. //sum of digit
  50. //We have to find number of M that satisfies this
  51.  
  52. ll val = n/i;
  53. ll sum_of_digit = val_digit(to_string(val));
  54. if(i==sum_of_digit && sz(to_string(val))==len){
  55. ans++;
  56. }
  57. }
  58. }
  59. cout<<ans<<endl;
  60.  
  61. }
  62.  
  63. int main(){
  64. IO;
  65. ll t =1;
  66. cin>>t;
  67. for(int i=1;i<=t;i++){
  68. // cout<<"Case #"<<i<<": ";
  69. solve();
  70. }
  71. return 0;
  72. }
Add Comment
Please, Sign In to add comment