fork download
  1.  
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. long long int b1,q,l,m,x,count=0,i=0;
  8. cin >> b1 >> q >> l >> m ;
  9. vector <int> vec;
  10. for(;i<m;i++){
  11. cin >> x;
  12. vec.push_back(x);
  13. }
  14. sort(vec.begin(),vec.end());
  15. x=b1;
  16. while(abs(x)<=l){
  17. if(b1==0){
  18. if(find(vec.begin(),vec.end(),b1)!=vec.end())
  19. {
  20. cout << 0 ;return 0;
  21. }
  22. else{
  23. cout << "inf" ;return 0;
  24. }
  25. }
  26. if(q==1){
  27. if(find(vec.begin(),vec.end(),b1)!=vec.end())
  28. {
  29. cout << 0 ;return 0;
  30. }
  31. else{
  32. cout << "inf" ;return 0;
  33. }
  34. }
  35. else if(q== -1){
  36. if(find(vec.begin(),vec.end(),b1)!=vec.end() && find(vec.begin(),vec.end(),b1*q)!=vec.end())
  37. {
  38. cout << 0 ;return 0;
  39. }
  40. else{
  41. cout << "inf" ;return 0;
  42. }
  43. }
  44. else if(q==0){
  45. if(find(vec.begin(),vec.end(),0)==vec.end()){
  46. cout << "inf" ; return 0;
  47. }
  48. else if(find(vec.begin(),vec.end(),b1)!=vec.end()){
  49. cout << 0 ; return 0;
  50. }
  51. else {
  52. cout << 1 ; return 0;
  53. }
  54.  
  55. }
  56. else if( find(vec.begin(),vec.end(),x)!=vec.end() ){
  57. x=x*q;
  58. }
  59. else{
  60. count++;x=x*q;
  61. }
  62. }
  63. cout << count ;
  64. return 0;
  65. }
  66.  
Success #stdin #stdout 0s 16056KB
stdin
123 1 2143435 4
123 11 -5453 141245
stdout
Standard output is empty