Advertisement
TimxAG

Untitled

Mar 29th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 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. bool isPower(double a, double b)
  14. {
  15. return trunc(log(a) / log(b)==(log(a) / log(b)));
  16. }
  17. int main()
  18. {
  19. double t,q;ll b,l,m,i,count=1,s=0,f=0;
  20. cin >> b >> q >> l >> m;
  21. for (i=0;i<m;i++)
  22. {
  23. cin >> t;// if (isPower(t/b,q)==1) s++;
  24. if ((isPower(abs(t/b),abs(q))==1) && (abs(t)<=abs(l))) { s++;
  25. if (b*pow(q,log(abs(t/b))/ log (abs(q)))!=t) s--; }
  26. //cout << s << endl;
  27. if (t==b) f=1;
  28. }
  29. if (abs(q)==1)
  30. {
  31. if ((f==1) || (b>l)) cout << 0; else cout << "inf";
  32. return 0;
  33. }
  34. // cout << endl;
  35. /*while (abs(b)<=l)
  36. {
  37. cout << b << " " << count << endl;
  38. b*=q; if (abs(b)<=l) count++;
  39. }*/
  40. int qq= trunc(abs(l/b));
  41. while (isPower(q,qq)==0)
  42. qq--;
  43. // cout << qq << endl;
  44. cout << trunc(log(qq)/log(q))-s+1;
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement