Ankit_132

D

Oct 14th, 2023
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7.  
  8. int main()
  9. {
  10.     int n;
  11.     string s, t;
  12.    
  13.     cin>>n>>s;
  14.    
  15.     vector<int> cnt(10);
  16.     vector<int> cnt2(10);
  17.    
  18.     for(auto e: s)      cnt[e-'0']++;
  19.    
  20.     int ans = 0;
  21.    
  22.     for(ll int i=0, x; i<=1e7; i++)
  23.     {
  24.         x = i*i;
  25.        
  26.         fill(cnt2.begin(), cnt2.end(), 0);
  27.        
  28.         t = to_string(x);
  29.    
  30.         for(auto e: t)      cnt2[e-'0']++;
  31.        
  32.         cnt2[0] = max(cnt2[0], cnt[0]);
  33.        
  34.         if(cnt == cnt2)     ans++;
  35.     }
  36.    
  37.     cout<<ans<<"\n";
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment