surajumang08

GGBUNNY

Jan 24th, 2017
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<algorithm>
  4. #include<vector>
  5. #include<cmath>
  6.  
  7. #define MAX 1e18
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.   int t,n,k;
  13.   cin>>t;
  14.   while(t--)
  15.   {
  16.     cin>>n>>k;
  17.     vector<long long> power;
  18.     long long num=1,ans=0;
  19.     //store all the powers of k in this array till end.
  20.     power.push_back(1);
  21.     for(int i=1; ;i++)
  22.     {
  23.       num*=k;
  24.       if(num>MAX || num<0 ) break;
  25.       power.push_back(num);
  26.       //cerr<<num<<" ";
  27.     }
  28.     //cerr<<endl;
  29.     //aceept n inputs.
  30.     for(int i=0;i<n;i++)
  31.     {
  32.       cin>>num;
  33.       if(binary_search(power.begin(),power.end(),num))
  34.         ans++;
  35.     }
  36.     cout<<ans<<endl;
  37.   }
  38.  
  39.  
  40. }
Add Comment
Please, Sign In to add comment