CF789B. Masha and geometric depression

  1 /*
  2  CF789B. Masha and geometric depression
  3  http://codeforces.com/contest/789/problem/B
  4  水题
  5  各种特判,贼烦
  6  */
  7 #include <cstdio>
  8 #include <algorithm>
  9 #include <cstring>
 10 #include <cmath>
 11 #include <vector>
 12 #include <queue>
 13 #include <map>
 14 #include <iostream>
 15 //#define test
 16 using namespace std;
 17 const int Nmax=1e6+7;
 18 long long num[Nmax];
 19 map<long long,int> f;
 20 int main()
 21 {
 22     #ifdef test
 23     #endif
 24     long long a,q,l;
 25     int m;
 26     scanf("%I64d%I64d%I64d%d",&a,&q,&l,&m);
 27     //cin>>a>>q>>l>>m;
 28     for(int i=1;i<=m;i++)
 29     {
 30         scanf("%I64d",&num[i]);
 31         f[ num[i] ]=1;
 32     }
 33     if(q==1LL)
 34     {
 35         if(abs(a)>abs(l))
 36         {
 37             printf("0\n");
 38             return 0;
 39         }
 40         if(f[a]==1)
 41             printf("0\n");
 42         else
 43             printf("inf\n");
 44         return 0;
 45     }
 46     if(q==-1LL)
 47     {
 48         if(abs(a)>abs(l))
 49         {
 50             printf("0\n");
 51             return 0;
 52         }
 53         if(f[a]==1 && f[-a]==1)
 54         {
 55             printf("0\n");
 56             return 0;
 57         }
 58         else if(f[a]==0 && f[-a]==0)
 59         {
 60             printf("inf\n");
 61             return 0;
 62         }
 63         else
 64         {
 65             printf("inf\n");
 66             return 0;
 67         }
 68     }
 69     if(abs(a)>abs(l))
 70     {
 71         printf("0\n");
 72         return 0;
 73     }
 74     if(q==0LL)
 75     {
 76         if(f[a]==0 && f[0]==1)
 77         {
 78             printf("1\n");
 79             return 0;
 80         }
 81         if(f[a]==1 && f[0]==1)
 82         {
 83             printf("0\n");
 84             return 0;
 85         }
 86         if(f[a]==0 && f[0]==0)
 87         {
 88             printf("inf\n");
 89             return 0;
 90         }
 91         if(f[a]==1 && f[0]==0)
 92         {
 93             printf("inf\n");
 94             return 0;
 95         }
 96         return 0;
 97     }
 98     if(a==0LL)
 99     {
100         if(f[a]==1)
101             printf("0\n");
102         else
103             printf("inf\n");
104         return 0;
105     }
106     //if(abs(a)>abs(l) && f[a]==0)
107     //{
108         //printf("0\n");
109         //return 0;
110     //}
111     //if(abs(a*q)>abs(l) && f[a*q]==0)
112     //{
113         //printf("1\n");
114         //return 0;
115     //}
116     //else if(abs(a*q)>abs(l))
117     //{
118         //printf("0\n");
119         //return 0;
120     //}
121     //if(q==1LL || q==-1LL || q==0LL)
122     //{
123         //printf("inf\n");
124         //return 0;
125     //}
126     //if(a==0LL)
127     //{
128         //printf("inf\n");
129         //return 0;
130     //}
131     long long ans=0LL;
132     while(1)
133     {
134         if(abs(a)>abs(l))
135             break;
136         //if(ans>=32LL)
137         //{
138             //printf("inf\n");
139             //return 0;
140         //}
141         if(f[a]==0)
142             ans++;
143         a*=q;
144     }
145     printf("%I64d\n",ans);
146     //cout<<ans<<endl;
147     return 0;
148 }

 

posted @ 2017-03-30 12:02  BBBob  阅读(1230)  评论(0编辑  收藏