C - Functions again CodeForces - 789C
C - Functions again
这道题考查了对Map的运用
#include<iostream> #include<cstdio> #include<map> #include<cmath> using namespace std; typedef long long ll; map<ll,ll> maps; ll b1,q,l,m,ans; int main() { cin>>b1>>q>>l>>m; for(int i=0;i<m;++i) { ll p; scanf("%lld",&p); maps[p]=1; } if(b1==0) { if(maps[0]==0) printf("inf"); else printf("0"); return 0; } else if(q==0) { if(abs(b1)>l) printf("0"); else if(maps[0]==0) printf("inf"); else if(maps[b1]==0) printf("1"); else printf("0"); return 0; } else if(q==1) { if(abs(b1)<=l&&maps[b1]==0) printf("inf"); else printf("0"); return 0; } else if(q==-1) { if(abs(b1)>l) printf("0"); else if(!maps[b1]||!maps[-b1]) printf("inf"); else printf("0"); return 0; } ll e=b1; while(abs(e)<=l) { if(maps[e]==0) ++ans; e*=q; } printf("%lld",ans); return 0; }