Advertisement
TimxAG

Untitled

Mar 29th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. int INF=2147483647;
  5. int inf=-2147483648;
  6. int mod=1000000007;
  7. #define read(x) cin >> x;
  8. #define fo(i,n) for(i=0;i<n;i++)
  9. #define one(x) cout<<(x)<<endl;
  10. #define two(a,b) cout<<(a)<<" "<<(b)<<endl;
  11. #define three(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl;
  12. #define four(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl;
  13. #define write(a,i) cout << a[i] << " ";
  14. bool isPower(double a, double b)
  15. {
  16. return trunc(log(a) / log(b)==(log(a) / log(b)));
  17. }
  18. int main()
  19. {
  20. double t,q;ll b,l,m,i,count=1,s=0,f=0;
  21. cin >> b >> q >> l >> m;
  22. for (i=0;i<m;i++)
  23. {
  24. cin >> t;// if (isPower(t/b,q)==1) s++;
  25. if ((isPower(abs(t/b),abs(q))==1) && (abs(t)<=abs(l))) { s++;//int bb=b;
  26. // for (int p=0;p<(log(abs(t/b))/ (log (abs(q))));p++)
  27. // bb*=q;
  28. if (b*pow(q,log(abs(t/b))/ log (abs(q)))!=t) s--; }
  29. //cout << s << endl;
  30. if (t==b) f=1;
  31. }
  32. if (abs(q)==1)
  33. {
  34. if ((f==1) || (b>l)) cout << 0; else cout << "inf";
  35. return 0;
  36. }
  37. // cout << endl;
  38. /*while (abs(b)<=l)
  39. {
  40. cout << b << " " << count << endl;
  41. b*=q; if (abs(b)<=l) count++;
  42. }*/
  43. int qq= trunc(abs(l/b));
  44. while (isPower(q,qq)==0)
  45. qq--;
  46. // cout << qq << endl;
  47. cout << trunc(log(qq)/log(q))-s+1;
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement