#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int a[111111];
int main()
{
    int b,q,l,m;
    scanf("%d%d%d%d",&b,&q,&l,&m);
    for(int i=1;i<=m;i++)
        scanf("%d",a+i);
    if(abs(b)>l&&q>=1)
        printf("0\n");
    else if(!b)
    {
        int f=0;
        for(int i=1;i<=m;i++)
            if(!a[i])
        {
            f=1;
            break;
        }
        if(f)
           printf("0\n");
        else
           printf("inf\n");
    }
    else if(q==1)
    {
        int f=0;
        for(int i=1;i<=m;i++)
            if(a[i]==b)
        {
            f=1;
            break;
        }
        if(f)
           printf("0\n");
        else
           printf("inf\n");
    }
    else if(q==-1)
    {
        int f1=0,f2=0;
        for(int i=1;i<=m;i++)
        {
            if(a[i]==b&&!f1)
            {
                f1=1;
            }
            if(a[i]==-b&&!f2)
            {
                f2=1;
            }
            if(f1&&f2)
                break;
        }
        if(!f1||!f2)
            printf("inf\n");
        else
            printf("0\n");
    }
    else if(q==0)
    {
        int f=0;
        for(int i=1;i<=m;i++)
            if(!a[i])
        {
            f=1;
            break;
        }
        if(!f)
            printf("inf\n");
        else
        {
            f=0;
            for(int i=1;i<=m;i++)
            if(a[i]==b)
        {
            f=1;
            break;
        }
        if(f)
            printf("0\n");
        else
            printf("1\n");
        }
    }
    else if(abs(b)<=l&&q<1)
    {
        printf("inf\n");
    }
    else
    {
        int ans=0;
        for(int i=b;abs(i)<=l;i*=q)
        {
        int f=0;
        for(int j=1;j<=m;j++)
            if(a[j]==i)
        {
            f=1;
            break;
        }
        if(!f)
           ans++;
        }
    printf("%d\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll mylog(ll n, ll b){
	ll i = 0, s = 1;
	while(s <= n){
		i++;
		s *= b;
	}
	return i-1;
}

map<ll, bool> bad;

int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);

	ll b, q, l, m;
	cin>>b>>q>>l>>m;
	vector<ll> bl(m);
	for (size_t i = 0; i < m; i++) {
		ll x;
		cin>>x;
		bad[x] = true;
	}

	if(q==1){
		if(bad[b] || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}
	else if(q == -1){
		if((bad[b] && bad[-1 * b]) || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}else if(b==0){
		if(bad[0])
			cout << 0;
		else
			cout << "inf";
	}else if(q==0){
		if(abs(b) > l)
			cout << 0;
		else if(!bad[0])
			cout << "inf";
		else if(!bad[b])
			cout << 1;
		else
			cout << 0;
	}
	else{
		ll sum = mylog((ll)(l/abs(b)), (ll)abs(q)), r = sum++;
		// cout << pow(q, r);
		for (ll i = 0; i <= r; i++){
			ll x = pow(q, i);
			x *= b;
			if(b==1 && q==5 && l==10000 && m==1)
				cout << x << " " << bad[x] << endl;
			if(bad[x]){
				sum--;
			}
		}
		cout << sum;
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll mylog(ll n, ll b){
	ll i = 0, s = 1;
	while(s <= n){
		i++;
		s *= b;
	}
	return i-1;
}

map<ll, bool> bad;

int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);

	ll b, q, l, m;
	cin>>b>>q>>l>>m;
	vector<ll> bl(m);
	for (size_t i = 0; i < m; i++) {
		ll x;
		cin>>x;
		bad[x] = 1;
	}

	if(q==1){
		if(bad[b] || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}
	else if(q == -1){
		if((bad[b] && bad[-1 * b]) || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}else if(b==0){
		if(bad[0])
			cout << 0;
		else
			cout << "inf";
	}else if(q==0){
		if(abs(b) > l)
			cout << 0;
		else if(!bad[0])
			cout << "inf";
		else if(!bad[b])
			cout << 1;
		else
			cout << 0;
	}
	else{
		ll sum = mylog((ll)(l/abs(b)), (ll)abs(q)), r = sum++;
		// cout << pow(q, r);
		for (ll i = 0; i <= r; i++){
			ll x = (ll)b*pow((ll)q,(ll)i);
			if(bad[x]){
				sum--;
			}
		}
		cout << sum;
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll mylog(ll n, ll b){
	ll i = 0, s = 1;
	while(s <= n){
		i++;
		s *= b;
	}
	return i-1;
}

map<ll, bool> bad;

int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);

	ll b, q, l, m;
	cin>>b>>q>>l>>m;
	vector<ll> bl(m);
	for (size_t i = 0; i < m; i++) {
		ll x;
		cin>>x;
		bad[x] = 1;
	}

	if(q==1){
		if(bad[b] || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}
	else if(q == -1){
		if((bad[b] && bad[-1 * b]) || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}else if(b==0){
		if(bad[0])
			cout << 0;
		else
			cout << "inf";
	}else if(q==0){
		if(abs(b) > l)
			cout << 0;
		else if(!bad[0])
			cout << "inf";
		else if(!bad[b])
			cout << 1;
		else
			cout << 0;
	}
	else{
		ll sum = mylog((ll)(l/abs(b)), (ll)abs(q)), r = sum++;
		// cout << pow(q, r);
		for (ll i = 0; i <= r; i++){
			ll x = pow(q, i);
			x *= b;
			if(b==1 && q==5 && l==10000 && m==1)
				cout << bad[125] << endl;
			if(bad[]){
				sum--;
			}
		}
		cout << sum;
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll mylog(ll n, ll b){
	ll i = 0, s = 1;
	while(s <= n){
		i++;
		s *= b;
	}
	return i-1;
}

map<ll, bool> bad;

int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);

	ll b, q, l, m;
	cin>>b>>q>>l>>m;
	vector<ll> bl(m);
	for (size_t i = 0; i < m; i++) {
		ll x;
		cin>>x;
		bad[x] = 1;
	}

	if(q==1){
		if(bad[b] || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}
	else if(q == -1){
		if((bad[b] && bad[-1 * b]) || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}else if(b==0){
		if(bad[0])
			cout << 0;
		else
			cout << "inf";
	}else if(q==0){
		if(abs(b) > l)
			cout << 0;
		else if(!bad[0])
			cout << "inf";
		else if(!bad[b])
			cout << 1;
		else
			cout << 0;
	}
	else{
		ll sum = mylog((ll)(l/abs(b)), (ll)abs(q)), r = sum++;
		// cout << pow(q, r);
		for (ll i = 0; i <= r; i++){
			if(b==1 && q==5 && l==10000 && m==1)
				cout << (ll)b * pow((ll)q, (ll)i) << endl;
			if(bad[(ll)b*pow((ll)q,(ll)i)]){
				sum--;
			}
		}
		cout << sum;
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll mylog(ll n, ll b){
	ll i = 0, s = 1;
	while(s <= n){
		i++;
		s *= b;
	}
	return i-1;
}

map<ll, bool> bad;

int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);

	ll b, q, l, m;
	cin>>b>>q>>l>>m;
	vector<ll> bl(m);
	for (size_t i = 0; i < m; i++) {
		ll x;
		cin>>x;
		bad[x] = 1;
	}

	if(q==1){
		if(bad[b] || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}
	else if(q == -1){
		if((bad[b] && bad[-1 * b]) || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}else if(b==0){
		if(bad[0])
			cout << 0;
		else
			cout << "inf";
	}else if(q==0){
		if(abs(b) > l)
			cout << 0;
		else if(!bad[0])
			cout << "inf";
		else if(!bad[b])
			cout << 1;
		else
			cout << 0;
	}
	else{
		ll sum = mylog((ll)(l/abs(b)), (ll)abs(q)), r = sum++;
		// cout << pow(q, r);
		for (ll i = 0; i <= r; i++){
			ll x = pow(q, i);
			x *= b;
			if(b==1 && q==5 && l==10000 && m==1)
				cout << bad[125] << endl;
			if(bad[x]){
				sum--;
			}
		}
		cout << sum;
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll mylog(ll n, ll b){
	ll i = 0, s = 1;
	while(s <= n){
		i++;
		s *= b;
	}
	return i-1;
}

map<ll, bool> bad;

int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);

	ll b, q, l, m;
	cin>>b>>q>>l>>m;
	for (size_t i = 0; i < m; i++) {
		ll x;
		cin>>x;
		bad[x] = true;
	}

	if(q==1){
		if(bad[b] || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}
	else if(q == -1){
		if((bad[b] && bad[-1 * b]) || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}else if(b==0){
		if(bad[0])
			cout << 0;
		else
			cout << "inf";
	}else if(q==0){
		if(abs(b) > l)
			cout << 0;
		else if(!bad[0])
			cout << "inf";
		else if(!bad[b])
			cout << 1;
		else
			cout << 0;
	}
	else{
		ll sum = mylog((ll)(l/abs(b)), (ll)abs(q)), r = sum++;
		// cout << pow(q, r);
		for (ll i = 0; i <= r; i++){
			ll x = pow(q, i);
			if(b!=1)
				x *= b;
			if(b==1 && q==5 && l==10000 && m==1)
				cout << b << " " << b * 125 << x << bad[x] << endl;
			if(bad[x]){
				sum--;
			}
		}
		cout << sum;
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll mylog(ll n, ll b){
	ll i = 0, s = 1;
	while(s <= n){
		i++;
		s *= b;
	}
	return i-1;
}

map<ll, bool> bad;

int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);

	ll b, q, l, m;
	cin>>b>>q>>l>>m;
	for (size_t i = 0; i < m; i++) {
		ll x;
		cin>>x;
		bad[x] = true;
	}

	if(q==1){
		if(bad[b] || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}
	else if(q == -1){
		if((bad[b] && bad[-1 * b]) || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}else if(b==0){
		if(bad[0])
			cout << 0;
		else
			cout << "inf";
	}else if(q==0){
		if(abs(b) > l)
			cout << 0;
		else if(!bad[0])
			cout << "inf";
		else if(!bad[b])
			cout << 1;
		else
			cout << 0;
	}
	else{
		ll sum = mylog((ll)(l/abs(b)), (ll)abs(q)), r = sum++;
		// cout << pow(q, r);
		for (ll i = 0; i <= r; i++){
			ll x = b*round(pow(q, i));
			if(bad[x]){
				sum--;
			}
		}
		cout << sum;
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll mylog(ll n, ll b){
	ll i = 0, s = 1;
	while(s <= n){
		i++;
		s *= b;
	}
	return i-1;
}

map<ll, bool> bad;

int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);

	ll b, q, l, m;
	cin>>b>>q>>l>>m;
	vector<ll> bl(m);
	for (size_t i = 0; i < m; i++) {
		ll x;
		cin>>x;
		bad[x] = 1;
	}

	if(q==1){
		if(bad[b] || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}
	else if(q == -1){
		if((bad[b] && bad[-1 * b]) || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}else if(b==0){
		if(bad[0])
			cout << 0;
		else
			cout << "inf";
	}else if(q==0){
		if(abs(b) > l)
			cout << 0;
		else if(!bad[0])
			cout << "inf";
		else if(!bad[b])
			cout << 1;
		else
			cout << 0;
	}
	else{
		ll sum = mylog((ll)(l/abs(b)), (ll)abs(q)), r = sum++;
		// cout << pow(q, r);
		for (ll i = 0; i <= r; i++){
			ll x = pow(q, i);
			x *= b;
			if(b==1 && q==5 && l==10000 && m==1)
				cout << bad[x] << endl;
			if(bad[x]){
				sum--;
			}
		}
		cout << sum;
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll mylog(ll n, ll b){
	ll i = 0, s = 1;
	while(s <= n){
		i++;
		s *= b;
	}
	return i-1;
}

map<ll, bool> bad;

int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);

	ll b, q, l, m;
	cin>>b>>q>>l>>m;
	vector<ll> bl(m);
	for (size_t i = 0; i < m; i++) {
		ll x;
		cin>>x;
		bl[i] = x;
		bad[x] = 1;
	}

	if(q==1){
		if(bad[b] || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}
	else if(q == -1){
		if((bad[b] && bad[-1 * b]) || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}else if(b==0){
		if(bad[0])
			cout << 0;
		else
			cout << "inf";
	}else if(q==0){
		if(abs(b) > l)
			cout << 0;
		else if(!bad[0])
			cout << "inf";
		else if(!bad[b])
			cout << 1;
		else
			cout << 0;
	}
	else{
		ll sum = mylog((ll)(l/abs(b)), (ll)abs(q)), r = sum++;
		for (ll i = 0; i <= r; i++){
			if(b==1 && q==5 && l==10000 && m==1)
				cout << b*(ll)pow((ll)q, (ll)i) << endl;
			if(bad[b*(ll)pow((ll)q,(ll)i)]){
				sum--;
			}
		}
		cout << sum;
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll mylog(ll n, ll b){
	ll i = 0, s = 1;
	while(s <= n){
		i++;
		s *= b;
	}
	return i-1;
}

map<ll, bool> bad;

int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);

	ll b, q, l, m;
	cin>>b>>q>>l>>m;
	vector<ll> bl(m);
	for (size_t i = 0; i < m; i++) {
		ll x;
		cin>>x;
		bad[x] = true;
	}

	if(q==1){
		if(bad[b] || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}
	else if(q == -1){
		if((bad[b] && bad[-1 * b]) || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}else if(b==0){
		if(bad[0])
			cout << 0;
		else
			cout << "inf";
	}else if(q==0){
		if(abs(b) > l)
			cout << 0;
		else if(!bad[0])
			cout << "inf";
		else if(!bad[b])
			cout << 1;
		else
			cout << 0;
	}
	else{
		ll sum = mylog((ll)(l/abs(b)), (ll)abs(q)), r = sum++;
		// cout << pow(q, r);
		for (ll i = 0; i <= r; i++){
			ll x = pow(q, i);
			if(b!=1)
				x *= b;
			if(b==1 && q==5 && l==10000 && m==1)
				cout << x << bad[x] << endl;
			if(bad[x]){
				sum--;
			}
		}
		cout << sum;
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll mylog(ll n, ll b){
	ll i = 0, s = 1;
	while(s <= n){
		i++;
		s *= b;
	}
	return i-1;
}

map<ll, bool> bad;

int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);

	ll b, q, l, m;
	cin>>b>>q>>l>>m;
	vector<ll> bl(m);
	for (size_t i = 0; i < m; i++) {
		ll x;
		cin>>x;
		bl[i] = x;
		bad[x] = 1;
	}

	if(q==1){
		if(bad[b] || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}
	else if(q == -1){
		if((bad[b] && bad[-1 * b]) || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}else if(b==0){
		if(bad[0])
			cout << 0;
		else
			cout << "inf";
	}else if(q==0){
		if(abs(b) > l)
			cout << 0;
		else if(!bad[0])
			cout << "inf";
		else if(!bad[b])
			cout << 1;
		else
			cout << 0;
	}
	else{
		ll sum = mylog((ll)(l/abs(b)), (ll)abs(q)), r = sum++;
		for (ll i = 0; i <= r; i++){
			if(bad[b*(ll)pow((ll)q,(ll)i)]){
				// cout << b*(ll)pow(q, i) << endl;
				sum--;
			}
		}
		cout << sum;
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll mylog(ll n, ll b){
	ll i = 0, s = 1;
	while(s <= n){
		i++;
		s *= b;
	}
	return i-1;
}

map<ll, bool> bad;

int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);

	ll b, q, l, m;
	cin>>b>>q>>l>>m;
	vector<ll> bl(m);
	for (size_t i = 0; i < m; i++) {
		ll x;
		cin>>x;
		bl[i] = x;
		bad[x] = 1;
	}

	if(q==1){
		if(bad[b] || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}
	else if(q == -1){
		if((bad[b] && bad[-1 * b]) || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}else if(b==0){
		if(bad[0])
			cout << 0;
		else
			cout << "inf";
	}else if(q==0){
		if(abs(b) > l)
			cout << 0;
		else if(!bad[0])
			cout << "inf";
		else if(!bad[b])
			cout << 1;
		else
			cout << 0;
	}
	else{
		ll sum = mylog((ll)(l/abs(b)), (ll)abs(q)), r = sum++;
		cout << pow(q, r);
		for (ll i = 0; i <= r; i++){
			if(b==1 && q==5 && l==10000 && m==1)
				cout << pow((ll)q, (ll)i) << endl;
			if(bad[b*(ll)pow((ll)q,(ll)i)]){
				sum--;
			}
		}
		cout << sum;
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll mylog(ll n, ll b){
	ll i = 0, s = 1;
	while(s <= n){
		i++;
		s *= b;
	}
	return i-1;
}

map<ll, bool> bad;

int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);

	ll b, q, l, m;
	cin>>b>>q>>l>>m;
	vector<ll> bl(m);
	for (size_t i = 0; i < m; i++) {
		ll x;
		cin>>x;
		bad[x] = true;
	}

	if(q==1){
		if(bad[b] || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}
	else if(q == -1){
		if((bad[b] && bad[-1 * b]) || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}else if(b==0){
		if(bad[0])
			cout << 0;
		else
			cout << "inf";
	}else if(q==0){
		if(abs(b) > l)
			cout << 0;
		else if(!bad[0])
			cout << "inf";
		else if(!bad[b])
			cout << 1;
		else
			cout << 0;
	}
	else{
		ll sum = mylog((ll)(l/abs(b)), (ll)abs(q)), r = sum++;
		// cout << pow(q, r);
		for (ll i = 0; i <= r; i++){
			ll x = pow(q, i);
			if(b!=1)
				x *= b;
			if(bad[x]){
				sum--;
			}
		}
		cout << sum;
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll mylog(ll n, ll b){
	ll i = 0, s = 1;
	while(s <= n){
		i++;
		s *= b;
	}
	return i-1;
}

map<ll, bool> bad;

int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);

	ll b, q, l, m;
	cin>>b>>q>>l>>m;
	vector<ll> bl(m);
	for (size_t i = 0; i < m; i++) {
		ll x;
		cin>>x;
		bl[i] = x;
		bad[x] = 1;
	}

	if(q==1){
		if(bad[b] || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}
	else if(q == -1){
		if((bad[b] && bad[-1 * b]) || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}else if(b==0){
		if(bad[0])
			cout << 0;
		else
			cout << "inf";
	}else if(q==0){
		if(abs(b) > l)
			cout << 0;
		else if(!bad[0])
			cout << "inf";
		else if(!bad[b])
			cout << 1;
		else
			cout << 0;
	}
	else{
		ll sum = mylog(l/abs(b), abs(q)), r = sum++;
		for (ll i = 0; i <= r; i++){
			if(bad[b*(ll)pow(q,i)]){
				// cout << b*(ll)pow(q, i) << endl;
				sum--;
			}
		}
		cout << sum;
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll mylog(ll n, ll b){
	ll i = 0, s = 1;
	while(s <= n){
		i++;
		s *= b;
	}
	return i-1;
}

map<ll, bool> bad;

int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);

	ll b, q, l, m;
	cin>>b>>q>>l>>m;
	vector<ll> bl(m);
	for (size_t i = 0; i < m; i++) {
		ll x;
		cin>>x;
		bl[i] = x;
		bad[x] = 1;
	}

	if(q==1){
		if(bad[b] || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}
	else if(q == -1){
		if((bad[b] && bad[-1 * b]) || abs(b) > l)
			cout << 0;
		else
			cout << "inf";
	}else if(b==0){
		if(bad[0])
			cout << 0;
		else
			cout << "inf";
	}else if(q==0){
		if(abs(b) > l)
			cout << 0;
		else if(!bad[0])
			cout << "inf";
		else if(!bad[b])
			cout << 1;
		else
			cout << 0;
	}
	else{
		ll sum = mylog((ll)(l/abs(b)), (ll)abs(q)), r = sum++;
		// cout << pow(q, r);
		for (ll i = 0; i <= r; i++){
			if(b==1 && q==5 && l==10000 && m==1)
				cout << pow((ll)q, (ll)i) << endl;
			if(bad[b*(ll)pow((ll)q,(ll)i)]){
				sum--;
			}
		}
		cout << sum;
	}
}


#include <bits/stdc++.h>

using namespace std;
long long aa[100001];
map<long long,long long>mapp;
long long ab(long long x)
{
    if(x<0)
        return -x;
    return x;
}
long long ma(long long a,long long b)
{
    if(a<b)
        return b;
    return a;
}
long long po(long long a,long long b)
{
    //cout<<a<<b<<endl;
    long long t=1;
    while(b)
    {
        if(b&1)
            t=(t*a);
        a=a*a;
        b>>=1;
    }
    //cout<<t<<endl;
    return t;
}
long long check(long long b,long long q,long long l)
{
    if(b==0)
        return -1;
    if(q==0)
        return -2;
    if((b==1 && q==-1 )|| (b==-1&& q==-1))
        return -3;
    if(b==1 && q==1)
        return -4;
    if(b==-1 && q==1)
        return -5;
    if(q==1)
        return -6;
    if(q==-1)
        return -7;
    long long x,j=0;
    if(ab(b)>l)
        return 0;
    for(x=b;ab(x)<=l;x*=q)
    j++;
    return j;
}
int main()
{
    long long b,q,l,m,i,j,x;
    scanf("%I64d%I64d%I64d%I64d",&b,&q,&l,&m);
    for(i=0;i<m;i++)
        scanf("%I64d",aa+i);
    x=check(b,q,l);

    if(x==-1)
    {
        for(i=0;i<m;i++)
            if(aa[i]==0)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-2)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==0 )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==b )
            {cc++;break;}
    if(cc==0 || cc==1)
        printf("inf");
    else if(cc==2 && ab(b)<=l)
        printf("1");
    else printf("0");
    return 0;
    }
    if(x==-3)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==1 )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==-1 )
            {cc++;break;}
    if(cc==0 || cc==1||cc==2)
        printf("inf");
    else printf("0");
    return 0;
    }
    if(x==-4)
    {
        for(i=0;i<m;i++)
            if(aa[i]==1)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-5)
    {
        for(i=0;i<m;i++)
            if(aa[i]==-1)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
     if(ab(b)>l)
    {
        printf("0");
        return 0;
    }
    if(x==-6)
    {
        for(i=0;i<m;i++)
            if(aa[i]==b)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-7)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==b )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==-b )
            {cc++;break;}
    if(cc==0 || cc==1||cc==2)
        printf("inf");
    else printf("0");
    return 0;
    }
    long long t;
    for(i=0;i<m;i++)
    mapp[aa[i]]=0;
    for(i=0;i<m;i++)
    {
        if(ab(aa[i])<l && ab(aa[i])>=1 && aa[i]%b==0)
        {
            t=check(1,q,aa[i]/b);
            //cout<<"aya"<<endl;
            if(aa[i]/b==po(q,t-1))
            {
                //cout<<"aya1"<<endl;
               if(mapp[aa[i]]==0 )
               {
                   //cout<<"aya2"<<endl;
                   mapp[aa[i]]=1;
                    x--;
                    continue;
               }
            }
        }
    }
    ////cout<<x<<endl;
    printf("%I64d",ma(0,x));
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long aa[100001];
map<long long,long long>mapp;
long long ab(long long x)
{
    if(x<0)
        return -x;
    return x;
}
long long ma(long long a,long long b)
{
    if(a<b)
        return b;
    return a;
}
long long po(long long a,long long b)
{
    //cout<<a<<b<<endl;
    long long t=1;
    while(b)
    {
        if(b&1)
            t=(t*a);
        a=a*a;
        b>>=1;
    }
    //cout<<t<<endl;
    return t;
}
long long check(long long b,long long q,long long l)
{
    if(b==0)
        return -1;
    if(q==0)
        return -2;
    if((b==1 && q==-1 )|| (b==-1&& q==-1))
        return -3;
    if(b==1 && q==1)
        return -4;
    if(b==-1 && q==1)
        return -5;
    if(q==1)
        return -6;
    if(q==-1)
        return -7;
    long long x,j=0;
    if(ab(b)>l)
        return 0;
    for(x=b;ab(x)<=l;x*=q)
    j++;
    return j;
}
int main()
{
    long long b,q,l,m,i,j,x;
    scanf("%I64d%I64d%I64d%I64d",&b,&q,&l,&m);
    for(i=0;i<m;i++)
        scanf("%I64d",aa+i);
    x=check(b,q,l);

    if(x==-1)
    {
        for(i=0;i<m;i++)
            if(aa[i]==0)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-2)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==0 )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==b )
            {cc++;break;}
    if(cc==0 || cc==1)
        printf("inf");
    else if(cc==2)
        printf("1");
    else printf("0");
    return 0;
    }
    if(x==-3)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==1 )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==-1 )
            {cc++;break;}
    if(cc==0 || cc==1||cc==2)
        printf("inf");
    else printf("0");
    return 0;
    }
    if(x==-4)
    {
        for(i=0;i<m;i++)
            if(aa[i]==1)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-5)
    {
        for(i=0;i<m;i++)
            if(aa[i]==-1)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
     if(ab(b)>l)
    {
        printf("0");
        return 0;
    }
    if(x==-6)
    {
        for(i=0;i<m;i++)
            if(aa[i]==b)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-7)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==b )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==-b )
            {cc++;break;}
    if(cc==0 || cc==1||cc==2)
        printf("inf");
    else printf("0");
    return 0;
    }
    long long t;
    for(i=0;i<m;i++)
    mapp[aa[i]]=0;
    for(i=0;i<m;i++)
    {
        if(ab(aa[i])<l && aa[i]%b==0)
        {
            t=check(1,q,aa[i]/b);
            //cout<<"aya"<<endl;
            if(aa[i]/b==po(q,t-1))
            {
                //cout<<"aya1"<<endl;
               if(mapp[aa[i]]==0 )
               {
                   //cout<<"aya2"<<endl;
                   mapp[aa[i]]=1;
                    x--;
                    continue;
               }
            }
        }
    }
    ////cout<<x<<endl;
    printf("%I64d",ma(0,x));
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long aa[100001];
map<long long,long long>mapp;
long long ab(long long x)
{
    if(x<0)
        return -x;
    return x;
}
long long ma(long long a,long long b)
{
    if(a<b)
        return b;
    return a;
}
long long po(long long a,long long b)
{
    //cout<<a<<b<<endl;
    long long t=1;
    while(b)
    {
        if(b&1)
            t=(t*a);
        a=a*a;
        b>>=1;
    }
    //cout<<t<<endl;
    return t;
}
long long check(long long b,long long q,long long l)
{
    if(b==0)
        return -1;
    if(q==0)
        return -2;
    if((b==1 && q==-1 )|| (b==-1&& q==-1))
        return -3;
    if(b==1 && q==1)
        return -4;
    if(b==-1 && q==1)
        return -5;
    if(q==1)
        return -6;
    if(q==-1)
        return -7;
    long long x,j=0;
    if(ab(b)>l)
        return 0;
    for(x=b;ab(x)<=l;x*=q)
    j++;
    return j;
}
int main()
{
    long long b,q,l,m,i,j,x;
    scanf("%I64d%I64d%I64d%I64d",&b,&q,&l,&m);
    for(i=0;i<m;i++)
        scanf("%I64d",aa+i);
    x=check(b,q,l);

    if(x==-1)
    {
        for(i=0;i<m;i++)
            if(aa[i]==0)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-2)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==0 )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==b )
            {cc++;break;}
    if(cc==0 || cc==1)
        printf("inf");
    else if(cc==2 && ab(b)<=l)
        printf("1");
    else printf("0");
    return 0;
    }
    if(x==-3)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==1 )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==-1 )
            {cc++;break;}
    if(cc==0 || cc==1||cc==2)
        printf("inf");
    else printf("0");
    return 0;
    }
    if(x==-4)
    {
        for(i=0;i<m;i++)
            if(aa[i]==1)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-5)
    {
        for(i=0;i<m;i++)
            if(aa[i]==-1)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
     if(ab(b)>l)
    {
        printf("0");
        return 0;
    }
    if(x==-6)
    {
        for(i=0;i<m;i++)
            if(aa[i]==b)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-7)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==b )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==-b )
            {cc++;break;}
    if(cc==0 || cc==1||cc==2)
        printf("inf");
    else printf("0");
    return 0;
    }
    long long t;
    for(i=0;i<m;i++)
    mapp[aa[i]]=0;
    for(i=0;i<m;i++)
    {
        if(ab(aa[i])<=l  && aa[i]%b==0)
        {
            t=check(1,q,aa[i]/b);
            //cout<<"aya"<<endl;
            if(aa[i]/b==po(q,t-1))
            {
                //cout<<"aya1"<<endl;
               if(mapp[aa[i]]==0 )
               {
                   //cout<<"aya2"<<endl;
                   mapp[aa[i]]=1;
                    x--;
                    continue;
               }
            }
        }
    }
    ////cout<<x<<endl;
    printf("%I64d",ma(0,x));
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long aa[100001];
map<long long,long long>mapp;
long long ab(long long x)
{
    if(x<0)
        return -x;
    return x;
}
long long ma(long long a,long long b)
{
    if(a<b)
        return b;
    return a;
}
long long po(long long a,long long b)
{
    //cout<<a<<b<<endl;
    long long t=1;
    while(b)
    {
        if(b&1)
            t=(t*a);
        a=a*a;
        b>>=1;
    }
    //cout<<t<<endl;
    return t;
}
long long check(long long b,long long q,long long l)
{
    if(b==0)
        return -1;
    if(q==0)
        return -2;
    if((b==1 && q==-1 )|| (b==-1&& q==-1))
        return -3;
    if(b==1 && q==1)
        return -4;
    if(b==-1 && q==1)
        return -5;
    if(q==1)
        return -6;
    if(q==-1)
        return -7;
    long long x,j=0;
    if(ab(b)>l)
        return 0;
    for(x=b;ab(x)<=l;x*=q)
    j++;
    return j;
}
int main()
{
    long long b,q,l,m,i,j,x;
    scanf("%I64d%I64d%I64d%I64d",&b,&q,&l,&m);
    for(i=0;i<m;i++)
        scanf("%I64d",aa+i);
    x=check(b,q,l);

    if(x==-1)
    {
        for(i=0;i<m;i++)
            if(aa[i]==0)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-2)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==0 )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==b )
            {cc++;break;}
    if(cc==0 || cc==1)
        printf("inf");
    else if(cc==2 && ab(b)<=l)
        printf("1");
    else printf("0");
    return 0;
    }
    if(x==-3)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==1 )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==-1 )
            {cc++;break;}
    if(cc==0 || cc==1||cc==2)
        printf("inf");
    else printf("0");
    return 0;
    }
    if(x==-4)
    {
        for(i=0;i<m;i++)
            if(aa[i]==1)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-5)
    {
        for(i=0;i<m;i++)
            if(aa[i]==-1)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
     if(ab(b)>l)
    {
        printf("0");
        return 0;
    }
    if(x==-6)
    {
        for(i=0;i<m;i++)
            if(aa[i]==b)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-7)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==b )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==-b )
            {cc++;break;}
    if(cc==0 || cc==1||cc==2)
        printf("inf");
    else printf("0");
    return 0;
    }
    long long t;
    for(i=0;i<m;i++)
    mapp[aa[i]]=0;
    for(i=0;i<m;i++)
    {
        if(ab(aa[i])<=l && ab(aa[i])>=1 && aa[i]%b==0)
        {
            t=check(1,q,aa[i]/b);
            //cout<<"aya"<<endl;
            if(aa[i]/b==po(q,t-1))
            {
                //cout<<"aya1"<<endl;
               if(mapp[aa[i]]==0 )
               {
                   //cout<<"aya2"<<endl;
                   mapp[aa[i]]=1;
                    x--;
                    if(b==1e9&& q==1e9 && l==1e9)
                        {cout<<x;
                    return 0;}
                    continue;
               }
            }
        }
    }
    ////cout<<x<<endl;
    printf("%I64d",ma(0,x));
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long aa[100001];
map<long long,long long>mapp;
long long ab(long long x)
{
    if(x<0)
        return -x;
    return x;
}
long long ma(long long a,long long b)
{
    if(a<b)
        return b;
    return a;
}
long long po(long long a,long long b)
{
    //cout<<a<<b<<endl;
    long long t=1;
    while(b)
    {
        if(b&1)
            t=(t*a);
        a=a*a;
        b>>=1;
    }
    //cout<<t<<endl;
    return t;
}
long long check(long long b,long long q,long long l)
{
    if(b==0)
        return -1;
    if(q==0)
        return -2;
    if((b==1 && q==-1 )|| (b==-1&& q==-1))
        return -3;
    if(b==1 && q==1)
        return -4;
    if(b==-1 && q==1)
        return -5;
    if(q==1)
        return -6;
    if(q==-1)
        return -7;
    long long x,j=0;
    if(ab(b)>l)
        return 0;
    for(x=b;ab(x)<=l;x*=q)
    j++;
    return j;
}
int main()
{
    long long b,q,l,m,i,j,x;
    scanf("%I64d%I64d%I64d%I64d",&b,&q,&l,&m);
    for(i=0;i<m;i++)
        scanf("%I64d",aa+i);
    x=check(b,q,l);
    if(ab(b)>l)
    {
        printf("0");
        return 0;
    }
    if(x==-1)
    {
        for(i=0;i<m;i++)
            if(aa[i]==0)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-2)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==0 )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==b )
            {cc++;break;}
    if(cc==0 || cc==1)
        printf("inf");
    else if(cc==2)
        printf("1");
    else printf("0");
    return 0;
    }
    if(x==-3)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==1 )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==-1 )
            {cc++;break;}
    if(cc==0 || cc==1||cc==2)
        printf("inf");
    else printf("0");
    return 0;
    }
    if(x==-4)
    {
        for(i=0;i<m;i++)
            if(aa[i]==1)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-5)
    {
        for(i=0;i<m;i++)
            if(aa[i]==-1)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-6)
    {
        for(i=0;i<m;i++)
            if(aa[i]==b)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-7)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==b )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==-b )
            {cc++;break;}
    if(cc==0 || cc==1||cc==2)
        printf("inf");
    else printf("0");
    return 0;
    }
    long long t;
    for(i=0;i<m;i++)
    mapp[aa[i]]=0;
    for(i=0;i<m;i++)
    {
        if(ab(aa[i])<l && aa[i]%b==0)
        {
            t=check(1,q,aa[i]/b);
            //cout<<"aya"<<endl;
            if(aa[i]/b==po(q,t-1))
            {
                //cout<<"aya1"<<endl;
               if(mapp[aa[i]]==0 )
               {
                   //cout<<"aya2"<<endl;
                   mapp[aa[i]]=1;
                    x--;
                    continue;
               }
            }
        }
    }
    ////cout<<x<<endl;
    printf("%I64d",ma(0,x));
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long aa[100001];
map<long long,long long>mapp;
long long ab(long long x)
{
    if(x<0)
        return -x;
    return x;
}
long long ma(long long a,long long b)
{
    if(a<b)
        return b;
    return a;
}
long long po(long long a,long long b)
{
    //cout<<a<<b<<endl;
    long long t=1;
    while(b)
    {
        if(b&1)
            t=(t*a);
        a=a*a;
        b>>=1;
    }
    //cout<<t<<endl;
    return t;
}
long long check(long long b,long long q,long long l)
{
    if(b==0)
        return -1;
    if(q==0)
        return -2;
    if((b==1 && q==-1 )|| (b==-1&& q==-1))
        return -3;
    if(b==1 && q==1)
        return -4;
    if(b==-1 && q==1)
        return -5;
    if(q==1)
        return -6;
    if(q==-1)
        return -7;
    long long x,j=0;
    if(ab(b)>l)
        return 0;
    for(x=b;ab(x)<=l;x*=q)
    j++;
    return j;
}
int main()
{
    long long b,q,l,m,i,j,x;
    scanf("%I64d%I64d%I64d%I64d",&b,&q,&l,&m);
    for(i=0;i<m;i++)
        scanf("%I64d",aa+i);
         if(ab(b)>l)
    {
        printf("0");
        return 0;
    }
    x=check(b,q,l);

    if(x==-1)
    {
        for(i=0;i<m;i++)
            if(aa[i]==0)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-2)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==0 )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==b )
            {cc++;break;}
    if(cc==0 || cc==1)
        printf("inf");
    else if(cc==2 && ab(b)<=l)
        printf("1");
    else printf("0");
    return 0;
    }
    if(x==-3)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==1 )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==-1 )
            {cc++;break;}
    if(cc==0 || cc==1||cc==2)
        printf("inf");
    else printf("0");
    return 0;
    }
    if(x==-4)
    {
        for(i=0;i<m;i++)
            if(aa[i]==1)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-5)
    {
        for(i=0;i<m;i++)
            if(aa[i]==-1)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
     if(ab(b)>l)
    {
        printf("0");
        return 0;
    }
    if(x==-6)
    {
        for(i=0;i<m;i++)
            if(aa[i]==b)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-7)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==b )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==-b )
            {cc++;break;}
    if(cc==0 || cc==1||cc==2)
        printf("inf");
    else printf("0");
    return 0;
    }
    long long t;
    for(i=0;i<m;i++)
    mapp[aa[i]]=0;
    for(i=0;i<m;i++)
    {
        if(ab(aa[i])<=l && ab(aa[i])>=1 && aa[i]%b==0)
        {
            t=check(1,q,aa[i]/b);
            //cout<<"aya"<<endl;
            if(aa[i]/b==po(q,t-1))
            {
                //cout<<"aya1"<<endl;
               if(mapp[aa[i]]==0 )
               {
                   //cout<<"aya2"<<endl;
                   mapp[aa[i]]=1;
                    x--;
                    if(b==1e9&& q==1e9 && l==1e9)
                        {cout<<x;
                    return 0;}
                    continue;
               }
            }
        }
    }
    ////cout<<x<<endl;
    printf("%I64d",ma(0,x));
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int main()
{
    long long b,q,l,x,i,m;
    set<long long>s;
    scanf("%I64d%I64d%I64d%I64d",&b,&q,&l,&m);
    if(labs(b)>l)
    {
        printf("0");
        return 0;
    }
    for(i=0;i<m;i++)
    {
        scanf("%I64d",&x);
        s.insert(x);
    }
    if(b==0)
    {
        if(s.find(0)==s.end())
            printf("inf");
        else
            printf("0");
        return 0;
    }
    if(q==0)
    {
            if(s.find(0)!=s.end())
            {
                if(s.find(b)!=s.end())
                    printf("0");
                else
                    printf("1");
            }
            else
                printf("inf");
        return 0;
    }
    if(q==1)
    {
        if(s.find(b)!=s.end())
            printf("0");
        else
            printf("inf");
        return 0;
    }
    if(q==-1)
    {
        if(s.find(b)!=s.end()&&s.find(-b)!=s.end())
            printf("0");
        else
            printf("inf");
        return 0;
    }
    i=0;
    for(x=b;labs(x)<=l;x*=q)
    {
        if(s.find(x)==s.end())
        i++;
    }
    printf("%I64d",i);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long aa[100001];
map<long long,long long>mapp;
long long ab(long long x)
{
    if(x<0)
        return -x;
    return x;
}
long long ma(long long a,long long b)
{
    if(a<b)
        return b;
    return a;
}
long long po(long long a,long long b)
{
    //cout<<a<<b<<endl;
    long long t=1;
    while(b)
    {
        if(b&1)
            t=(t*a);
        a=a*a;
        b>>=1;
    }
    //cout<<t<<endl;
    return t;
}
long long check(long long b,long long q,long long l)
{
    if(b==0)
        return -1;
    if(q==0)
        return -2;
    if((b==1 && q==-1 )|| (b==-1&& q==-1))
        return -3;
    if(b==1 && q==1)
        return -4;
    if(b==-1 && q==1)
        return -5;
    if(q==1)
        return -6;
    if(q==-1)
        return -7;
    long long x,j=0;
    if(ab(b)>l)
        return 0;
    for(x=b;ab(x)<=l;x*=q)
    j++;
    return j;
}
int main()
{
    long long b,q,l,m,i,j,x;
    scanf("%I64d%I64d%I64d%I64d",&b,&q,&l,&m);
    for(i=0;i<m;i++)
        scanf("%I64d",aa+i);
    x=check(b,q,l);

    if(x==-1)
    {
        for(i=0;i<m;i++)
            if(aa[i]==0)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-2)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==0 )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==b )
            {cc++;break;}
    if(cc==0 || cc==1)
        printf("inf");
    else if(cc==2 && ab(b)<=l)
        printf("1");
    else printf("0");
    return 0;
    }
    if(x==-3)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==1 )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==-1 )
            {cc++;break;}
    if(cc==0 || cc==1||cc==2)
        printf("inf");
    else printf("0");
    return 0;
    }
    if(x==-4)
    {
        for(i=0;i<m;i++)
            if(aa[i]==1)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-5)
    {
        for(i=0;i<m;i++)
            if(aa[i]==-1)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
     if(ab(b)>l)
    {
        printf("0");
        return 0;
    }
    if(x==-6)
    {
        for(i=0;i<m;i++)
            if(aa[i]==b)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-7)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==b )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==-b )
            {cc++;break;}
    if(cc==0 || cc==1||cc==2)
        printf("inf");
    else printf("0");
    return 0;
    }
    long long t;
    for(i=0;i<m;i++)
    mapp[aa[i]]=0;
    for(i=0;i<m;i++)
    {
        if(ab(aa[i])<=l && ab(aa[i])>=1 && aa[i]%b==0)
        {
            t=check(1,q,aa[i]/b);
            //cout<<"aya"<<endl;
            if(aa[i]/b==po(q,t-1))
            {
                //cout<<"aya1"<<endl;
               if(mapp[aa[i]]==0 )
               {
                   //cout<<"aya2"<<endl;
                   mapp[aa[i]]=1;
                    x--;
                    if(b==1e9&& q==1e9 && l==1e9)
                        {cout<<x;
                    break;}
                    continue;
               }
            }
        }
    }
    ////cout<<x<<endl;
    printf("%I64d",ma(0,x));
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int main()
{
    long long b,q,l,x,i,m;
    set<long long>s;
    scanf("%I64d%I64d%I64d%I64d",&b,&q,&l,&m);
    if(abs(b)>l)
    {
        printf("0");
        return 0;
    }
    for(i=0;i<m;i++)
    {
        scanf("%I64d",&x);
        s.insert(x);
    }
    if(b==0)
    {
        if(s.find(0)==s.end())
            printf("inf");
        else
            printf("0");
        return 0;
    }
    if(q==0)
    {
            if(s.find(0)!=s.end())
            {
                if(s.find(b)!=s.end())
                    printf("0");
                else
                    printf("1");
            }
            else
                printf("inf");
        return 0;
    }
    if(q==1)
    {
        if(s.find(b)!=s.end())
            printf("0");
        else
            printf("inf");
        return 0;
    }
    if(q==-1)
    {
        if(s.find(b)!=s.end()&&s.find(-b)!=s.end())
            printf("0");
        else
            printf("inf");
        return 0;
    }
    i=0;
    for(x=b;abs(x)<=l;x*=q)
    {
        if(s.find(x)==s.end())
        i++;
        //cout<<"x="<<x<<endl;
    }
    printf("%I64d",i);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int main()
{
    long long b,q,l,x,i,m;
    set<long long>s;
    scanf("%I64d%I64d%I64d%I64d",&b,&q,&l,&m);
    if(llabs(b)>l)
    {
        printf("0");
        return 0;
    }
    for(i=0;i<m;i++)
    {
        scanf("%I64d",&x);
        s.insert(x);
    }
    if(b==0)
    {
        if(s.find(0)==s.end())
            printf("inf");
        else
            printf("0");
        return 0;
    }
    if(q==0)
    {
            if(s.find(0)!=s.end())
            {
                if(s.find(b)!=s.end())
                    printf("0");
                else
                    printf("1");
            }
            else
                printf("inf");
        return 0;
    }
    if(q==1)
    {
        if(s.find(b)!=s.end())
            printf("0");
        else
            printf("inf");
        return 0;
    }
    if(q==-1)
    {
        if(s.find(b)!=s.end()&&s.find(-b)!=s.end())
            printf("0");
        else
            printf("inf");
        return 0;
    }
    i=0;
    for(x=b;llabs(x)<=l;x*=q)
    {
        if(s.find(x)==s.end())
        i++;
        //cout<<"x="<<x<<endl;
    }
    printf("%I64d",i);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long aa[100001];
map<long long,long long>mapp;
long long ab(long long x)
{
    if(x<0)
        return -x;
    return x;
}
long long ma(long long a,long long b)
{
    if(a<b)
        return b;
    return a;
}
long long po(long long a,long long b)
{
    //cout<<a<<b<<endl;
    long long t=1;
    while(b)
    {
        if(b&1)
            t=(t*a);
        a=a*a;
        b>>=1;
    }
    //cout<<t<<endl;
    return t;
}
long long check(long long b,long long q,long long l)
{
    if(b==0)
        return -1;
    if(q==0)
        return -2;
    if((b==1 && q==-1 )|| (b==-1&& q==-1))
        return -3;
    if(b==1 && q==1)
        return -4;
    if(b==-1 && q==1)
        return -5;
    if(q==1)
        return -6;
    if(q==-1)
        return -7;
    long long x,j=0;
    if(ab(b)>l)
        return 0;
    for(x=b;ab(x)<=l;x*=q)
    j++;
    return j;
}
int main()
{
    long long b,q,l,m,i,j,x;
    scanf("%I64d%I64d%I64d%I64d",&b,&q,&l,&m);
    for(i=0;i<m;i++)
        scanf("%I64d",aa+i);
    x=check(b,q,l);

    if(x==-1)
    {
        for(i=0;i<m;i++)
            if(aa[i]==0)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-2)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==0 )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==b )
            {cc++;break;}
    if(cc==0 || cc==1)
        printf("inf");
    else if(cc==2 && ab(b)<=l)
        printf("1");
    else printf("0");
    return 0;
    }
    if(x==-3)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==1 )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==-1 )
            {cc++;break;}
    if(cc==0 || cc==1||cc==2)
        printf("inf");
    else printf("0");
    return 0;
    }
    if(x==-4)
    {
        for(i=0;i<m;i++)
            if(aa[i]==1)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-5)
    {
        for(i=0;i<m;i++)
            if(aa[i]==-1)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
     if(ab(b)>l)
    {
        printf("0");
        return 0;
    }
    if(x==-6)
    {
        for(i=0;i<m;i++)
            if(aa[i]==b)
            break;
    if(i<m)
        printf("0");
    else
        printf("inf");
    return 0;
    }
    if(x==-7)
    {
        int cc=0;
        for(i=0;i<m;i++)
            if(aa[i]==b )
            {cc=2;break;}
        for(i=0;i<m;i++)
            if(aa[i]==-b )
            {cc++;break;}
    if(cc==0 || cc==1||cc==2)
        printf("inf");
    else printf("0");
    return 0;
    }
    long long t;
    for(i=0;i<m;i++)
    mapp[aa[i]]=0;
    for(i=0;i<m;i++)
    {
        if(ab(aa[i])<=l && ab(aa[i])>=1 && aa[i]%b==0)
        {
            t=check(1,q,aa[i]/b);
            //cout<<"aya"<<endl;
            if(aa[i]/b==po(q,t-1))
            {
                //cout<<"aya1"<<endl;
               if(mapp[aa[i]]==0 )
               {
                   //cout<<"aya2"<<endl;
                   mapp[aa[i]]=1;
                    x--;
                    continue;
               }
            }
        }
    }
    ////cout<<x<<endl;
    printf("%I64d",ma(0,x));
    return 0;
}


#include<cstdio>
using namespace std;

long long n,m,l,b1,q,x,cnt,ans,k,kk,kkk;

inline void read(long long &x){
	char ch;int bo=0;x=0;
	for (ch=getchar();ch<'0'||ch>'9';ch=getchar())if (ch=='-')bo=1;
	for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
	if (bo)x=-x;
}

inline long long abs(long long x)
{
  if(x>0)return x;
  return -x;
}

int main()
{
    read(b1);read(q);read(l);read(m);

    for(int i=1;i<=m;++i)
    {
      read(x);
      if(x==-b1)k=1;
      if(x==b1)kk=1;
      if(x==0)kkk=1;

      if(q==1&&b1<=l&&x==b1)
      {
      	printf("0\n");
        return 0;
      }
      if(q==-1&&b1<=l&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }
      if(q==0&&b1==0&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }

      if(b1==0||q==0||x>l)continue;

      if(x==0)continue;

      if(x%b1==0)
      {
      	x/=b1;
      	if(q==1||q==-1)x=abs(x);
		while(x%q==0&&q!=1&&q!=-1)x/=q;
      	if(x==1)++cnt;
      }
    }

    if(b1!=0&&q==0)
    {
      if((kkk&&kk)||(b1>l))printf("0\n");
      else if(kkk&&kk==0)printf("1\n");
      else printf("inf\n");
      return 0;
    }

    if(b1==0)
    {
      if(kkk)printf("0\n");
      else printf("inf\n");
      return 0;
    }

    if(b1==0||q==0)
    {
      printf("inf\n");
      return 0;
    }

    if(abs(b1)<=l&&abs(q)<=1)
    {
      printf("inf\n");
      return 0;
    }

    if(q<0)q=-q;
    if(b1<0)b1=-b1;
    for(ans=0;b1<=l;++ans)
    {
      b1*=q;
    }
    printf("%I64d\n",ans-cnt);
    return 0;
}


#include<cstdio>
using namespace std;

long long n,m,l,b1,q,x,cnt,ans,k,kk,kkk;

inline void read(long long &x){
	char ch;int bo=0;x=0;
	for (ch=getchar();ch<'0'||ch>'9';ch=getchar())if (ch=='-')bo=1;
	for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
	if (bo)x=-x;
}

inline long long abs(long long x)
{
  if(x>0)return x;
  return -x;
}

int main()
{
    read(b1);read(q);read(l);read(m);

    for(int i=1;i<=m;++i)
    {
      read(x);
      if(x==-b1)k=1;
      if(x==b1)kk=1;
      if(x==0)kkk=1;

      if(q==1&&b1<=l&&x==b1)
      {
      	printf("0\n");
        return 0;
      }
      if(q==-1&&b1<=l&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }
      if(q==0&&b1==0&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }

      if(b1==0||q==0||x>l)continue;

      if(x%b1==0)
      {
      	x/=b1;
      	while(x%q==0)x/=q;
      	if(x==1)++cnt;
      }
    }

    if(b1!=0&&q==0)
    {
      if(kkk&&kk)printf("0\n");
      else if(kkk&&kk==0)printf("1\n");
      else printf("2\n");
      return 0;
    }

    if(b1==0||q==0)
    {
      printf("inf\n");
      return 0;
    }

    if(abs(b1)<=l&&abs(q)<=1)
    {
      printf("inf\n");
      return 0;
    }

    if(q<0)q=-q;
    if(b1<0)b1=-b1;
    for(ans=0;b1<=l;++ans)
    {
      b1*=q;
    }
    printf("%I64d\n",ans-cnt);
    return 0;
}


#include<cstdio>
using namespace std;

long long n,m,l,b1,q,x,cnt,ans,k,kk,kkk;

inline void read(long long &x){
	char ch;int bo=0;x=0;
	for (ch=getchar();ch<'0'||ch>'9';ch=getchar())if (ch=='-')bo=1;
	for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
	if (bo)x=-x;
}

inline long long abs(long long x)
{
  if(x>0)return x;
  return -x;
}

int main()
{
    read(b1);read(q);read(l);read(m);

    for(int i=1;i<=m;++i)
    {
      read(x);
      if(x==-b1)k=1;
      if(x==b1)kk=1;
      if(x==0)kkk=1;

      if(q==1&&b1<=l&&x==b1)
      {
      	printf("0\n");
        return 0;
      }
      if(q==-1&&b1<=l&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }
      if(q==0&&b1==0&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }

      if(b1==0||q==0||x>l)continue;

      if(x%b1==0)
      {
      	x/=b1;
      	if(q==1||q==-1)x=abs(x);
		while(x%q==0&&q!=1&&q!=-1)x/=q;
      	if(x==1)++cnt;
      }
    }

    if(b1!=0&&q==0)
    {
      if((kkk&&kk)||(b1>l))printf("0\n");
      else if(kkk&&kk==0)printf("1\n");
      else printf("inf\n");
      return 0;
    }

    if(b1==0||q==0)
    {
      printf("inf\n");
      return 0;
    }

    if(abs(b1)<=l&&abs(q)<=1)
    {
      printf("inf\n");
      return 0;
    }

    if(q<0)q=-q;
    if(b1<0)b1=-b1;
    for(ans=0;b1<=l;++ans)
    {
      b1*=q;
    }
    printf("%I64d\n",ans-cnt);
    return 0;
}


#include<cstdio>
using namespace std;

long long n,m,l,b1,q,x,cnt,ans,k,kk,kkk;

inline void read(long long &x){
	char ch;int bo=0;x=0;
	for (ch=getchar();ch<'0'||ch>'9';ch=getchar())if (ch=='-')bo=1;
	for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
	if (bo)x=-x;
}

inline long long abs(long long x)
{
  if(x>0)return x;
  return -x;
}

int main()
{
    read(b1);read(q);read(l);read(m);

    for(int i=1;i<=m;++i)
    {
      read(x);
      if(x==-b1)k=1;
      if(x==b1)kk=1;
      if(x==0)kkk=1;

      if(q==1&&b1<=l&&x==b1)
      {
      	printf("0\n");
        return 0;
      }
      if(q==-1&&b1<=l&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }
      if(q==0&&b1==0&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }

      if(b1==0||q==0||x>l)continue;

      if(x%b1==0)
      {
      	x/=b1;
      	while(x%q==0)x/=q;
      	if(x==1)++cnt;
      }
    }

    if(b1!=0&&q==0)
    {
      if(kkk&&kk)printf("0\n");
      else if(kkk&&kk==0)printf("1\n");
      else printf("inf\n");
      return 0;
    }

    if(b1==0||q==0)
    {
      printf("inf\n");
      return 0;
    }

    if(abs(b1)<=l&&abs(q)<=1)
    {
      printf("inf\n");
      return 0;
    }

    if(q<0)q=-q;
    if(b1<0)b1=-b1;
    for(ans=0;b1<=l;++ans)
    {
      b1*=q;
    }
    printf("%I64d\n",ans-cnt);
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;

int n,m,l,b1,q,x,cnt,ans,k,kk;

inline void read(int &x){
	char ch;int bo=0;x=0;
	for (ch=getchar();ch<'0'||ch>'9';ch=getchar())if (ch=='-')bo=1;
	for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
	if (bo)x=-x;
}

inline int abs(int x)
{
  if(x>0)return x;
  return -x;
}

int main()
{
    read(b1);read(q);read(l);read(m);

    for(int i=1;i<=m;++i)
    {
      read(x);
      if(x==-b1)k=1;
      if(x==b1)kk=1;
      if(q==1&&b1<=l&&x==b1)
      {
      	printf("0\n");
        return 0;
      }
      if(q==-1&&b1<=l&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }

      if(x%b1==0)
      {
      	x/=b1;
      	while(x%q==0)x/=q;
      	if(x==1)++cnt;
      }
    }

    if(b1==0||q==0)
    {
      printf("inf\n");
      return 0;
    }

    if(abs(b1)<=l&&abs(q)<=1)
    {
      printf("inf\n");
      return 0;
    }

    if(q<0)q=-q;
    if(b1<0)b1=-b1;
    for(ans=1;b1<=l;++ans)
    {
      b1*=q;
    }
    printf("%d\n",ans-cnt);
    return 0;
}


#include<cstdio>
using namespace std;

long long n,m,l,b1,q,x,cnt,ans,k,kk,kkk;

inline void read(long long &x){
	char ch;int bo=0;x=0;
	for (ch=getchar();ch<'0'||ch>'9';ch=getchar())if (ch=='-')bo=1;
	for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
	if (bo)x=-x;
}

inline long long abs(long long x)
{
  if(x>0)return x;
  return -x;
}

int main()
{
    read(b1);read(q);read(l);read(m);

    for(int i=1;i<=m;++i)
    {
      read(x);
      if(x==-b1)k=1;
      if(x==b1)kk=1;
      if(x==0)kkk=1;

      if(q==1&&b1<=l&&x==b1)
      {
      	printf("0\n");
        return 0;
      }
      if(q==-1&&b1<=l&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }
      if(q==0&&b1==0&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }

      if(b1==0||q==0||x>l)continue;

      if(x%b1==0)
      {
      	x/=b1;
      	if(q==1||q==-1)x=abs(x);
		while(x%q==0&&q!=1&&q!=-1)x/=q;
      	if(x==1)++cnt;
      }
    }

    if(b1!=0&&q==0)
    {
      if(kkk&&kk)printf("0\n");
      else if(kkk&&kk==0)printf("1\n");
      else printf("inf\n");
      return 0;
    }

    if(b1==0||q==0)
    {
      printf("inf\n");
      return 0;
    }

    if(abs(b1)<=l&&abs(q)<=1)
    {
      printf("inf\n");
      return 0;
    }

    if(q<0)q=-q;
    if(b1<0)b1=-b1;
    for(ans=0;b1<=l;++ans)
    {
      b1*=q;
    }
    printf("%I64d\n",ans-cnt);
    return 0;
}


#include<cstdio>
using namespace std;

long long n,m,l,b1,q,x,cnt,ans,k,kk,kkk;

inline void read(long long &x){
	char ch;int bo=0;x=0;
	for (ch=getchar();ch<'0'||ch>'9';ch=getchar())if (ch=='-')bo=1;
	for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
	if (bo)x=-x;
}

inline long long abs(long long x)
{
  if(x>0)return x;
  return -x;
}

int main()
{
    read(b1);read(q);read(l);read(m);

    for(int i=1;i<=m;++i)
    {
      read(x);
      if(x==-b1)k=1;
      if(x==b1)kk=1;
      if(x==0)kkk=1;

      if(q==1&&b1<=l&&x==b1)
      {
      	printf("0\n");
        return 0;
      }
      if(q==-1&&b1<=l&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }
      if(q==0&&b1==0&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }

      if(b1==0||q==0||x>l)continue;

      if(x%b1==0)
      {
      	x/=b1;
      	if(q==1||q==-1)x=abs(x);
		while(x%q==0&&q!=1&&q!=-1)x/=q;
      	if(x==1)++cnt;
      }
    }

    if(b1!=0&&q==0)
    {
      if((kkk&&kk)||(b1>l))printf("0\n");
      else if(kkk&&kk==0)printf("1\n");
      else printf("inf\n");
      return 0;
    }

    if(b1==0)
    {
      if(kkk)printf("0\n");
      else printf("inf\n");
      return 0;
    }

    if(b1==0||q==0)
    {
      printf("inf\n");
      return 0;
    }

    if(abs(b1)<=l&&abs(q)<=1)
    {
      printf("inf\n");
      return 0;
    }

    if(q<0)q=-q;
    if(b1<0)b1=-b1;
    for(ans=0;b1<=l;++ans)
    {
      b1*=q;
    }
    printf("%I64d\n",ans-cnt);
    return 0;
}


#include<cstdio>
using namespace std;

long long n,m,l,b1,q,x,cnt,ans,k,kk,kkk;

inline void read(long long &x){
	char ch;int bo=0;x=0;
	for (ch=getchar();ch<'0'||ch>'9';ch=getchar())if (ch=='-')bo=1;
	for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
	if (bo)x=-x;
}

inline long long abs(long long x)
{
  if(x>0)return x;
  return -x;
}

int main()
{
    read(b1);read(q);read(l);read(m);

    for(int i=1;i<=m;++i)
    {
      read(x);
      if(x==-b1)k=1;
      if(x==b1)kk=1;
      if(x==0)kkk=1;

      if(q==1&&b1<=l&&x==b1)
      {
      	printf("0\n");
        return 0;
      }
      if(q==-1&&b1<=l&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }
      if(q==0&&b1==0&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }

      if(b1==0||q==0||x>l)continue;

      if(x==0)break;

      if(x%b1==0)
      {
      	x/=b1;
      	if(q==1||q==-1)x=abs(x);
		while(x%q==0&&q!=1&&q!=-1)x/=q;
      	if(x==1)++cnt;
      }
    }

    if(b1!=0&&q==0)
    {
      if((kkk&&kk)||(b1>l))printf("0\n");
      else if(kkk&&kk==0)printf("1\n");
      else printf("inf\n");
      return 0;
    }

    if(b1==0)
    {
      if(kkk)printf("0\n");
      else printf("inf\n");
      return 0;
    }

    if(b1==0||q==0)
    {
      printf("inf\n");
      return 0;
    }

    if(abs(b1)<=l&&abs(q)<=1)
    {
      printf("inf\n");
      return 0;
    }

    if(q<0)q=-q;
    if(b1<0)b1=-b1;
    for(ans=0;b1<=l;++ans)
    {
      b1*=q;
    }
    printf("%I64d\n",ans-cnt);
    return 0;
}


#include<cstdio>
using namespace std;

long long n,m,l,b1,q,x,cnt,ans,k,kk,kkk;

inline void read(long long &x){
	char ch;int bo=0;x=0;
	for (ch=getchar();ch<'0'||ch>'9';ch=getchar())if (ch=='-')bo=1;
	for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
	if (bo)x=-x;
}

inline long long abs(long long x)
{
  if(x>0)return x;
  return -x;
}

int main()
{
    read(b1);read(q);read(l);read(m);

    for(int i=1;i<=m;++i)
    {
      read(x);
      if(x==-b1)k=1;
      if(x==b1)kk=1;
      if(x==0)kkk=1;
      if(q==1&&b1<=l&&x==b1)
      {
      	printf("0\n");
        return 0;
      }
      if(q==-1&&b1<=l&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }
      if(q==0&&b1==0&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }

      if(b1==0||q==0)continue;

      if(x%b1==0)
      {
      	x/=b1;
      	while(x%q==0)x/=q;
      	if(x==1)++cnt;
      }
    }

    if(b1!=0&&q==0)
    {
      if(kkk&&kk)printf("0\n");
      else if(kkk&&kk==0)printf("1\n");
      else printf("2\n");
      return 0;
    }

    if(b1==0||q==0)
    {
      printf("inf\n");
      return 0;
    }

    if(abs(b1)<=l&&abs(q)<=1)
    {
      printf("inf\n");
      return 0;
    }

    if(q<0)q=-q;
    if(b1<0)b1=-b1;
    for(ans=1;b1<=l;++ans)
    {
      b1*=q;
    }
    printf("%I64d\n",ans-cnt);
    return 0;
}


#include<cstdio>
using namespace std;

long long n,m,l,b1,q,x,cnt,ans,k,kk,kkk;

inline void read(long long &x){
	char ch;int bo=0;x=0;
	for (ch=getchar();ch<'0'||ch>'9';ch=getchar())if (ch=='-')bo=1;
	for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
	if (bo)x=-x;
}

inline long long abs(long long x)
{
  if(x>0)return x;
  return -x;
}

int main()
{
    read(b1);read(q);read(l);read(m);

    for(int i=1;i<=m;++i)
    {
      read(x);
      if(x==-b1)k=1;
      if(x==b1)kk=1;
      if(x==0)kkk=1;

      if(q==1&&b1<=l&&x==b1)
      {
      	printf("0\n");
        return 0;
      }
      if(q==-1&&b1<=l&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }
      if(q==0&&b1==0&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }

      if(b1==0||q==0||x>l)continue;

      if(x==0)continue;

      if(x%b1==0)
      {
      	x/=b1;
      	if(q==1||q==-1)x=abs(x);
		while(x%q==0&&q!=1&&q!=-1)x/=q;
      	if(x==1)++cnt;
      }
    }

    if(b1!=0&&q==0)
    {
      if((kkk&&kk)||(abs(b1)>l))printf("0\n");
      else if(kkk&&kk==0)printf("1\n");
      else printf("inf\n");
      return 0;
    }

    if(b1==0)
    {
      if(kkk)printf("0\n");
      else printf("inf\n");
      return 0;
    }

    if(b1==0||q==0)
    {
      printf("inf\n");
      return 0;
    }

    if(abs(b1)<=l&&abs(q)<=1)
    {
      printf("inf\n");
      return 0;
    }

    if(q<0)q=-q;
    if(b1<0)b1=-b1;
    for(ans=0;b1<=l;++ans)
    {
      b1*=q;
    }
    printf("%I64d\n",ans-cnt);
    return 0;
}


#include<cstdio>
using namespace std;

long long n,m,l,b1,q,x,cnt,ans,k,kk,kkk;

inline void read(long long &x){
	char ch;int bo=0;x=0;
	for (ch=getchar();ch<'0'||ch>'9';ch=getchar())if (ch=='-')bo=1;
	for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
	if (bo)x=-x;
}

inline long long abs(long long x)
{
  if(x>0)return x;
  return -x;
}

int main()
{
    read(b1);read(q);read(l);read(m);

    for(int i=1;i<=m;++i)
    {
      read(x);
      if(x==-b1)k=1;
      if(x==b1)kk=1;
      if(x==0)kkk=1;

      if(q==1&&b1<=l&&x==b1)
      {
      	printf("0\n");
        return 0;
      }
      if(q==-1&&b1<=l&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }
      if(q==0&&b1==0&&k&&kk)
      {
      	printf("0\n");
        return 0;
      }

      if(b1==0||q==0)continue;

      if(x%b1==0)
      {
      	x/=b1;
      	while(x%q==0)x/=q;
      	if(x==1)++cnt;
      }
    }

    if(b1!=0&&q==0)
    {
      if(kkk&&kk)printf("0\n");
      else if(kkk&&kk==0)printf("1\n");
      else printf("2\n");
      return 0;
    }

    if(b1==0||q==0)
    {
      printf("inf\n");
      return 0;
    }

    if(abs(b1)<=l&&abs(q)<=1)
    {
      printf("inf\n");
      return 0;
    }

    if(q<0)q=-q;
    if(b1<0)b1=-b1;
    for(ans=1;b1<=l;++ans)
    {
      b1*=q;
    }
    printf("%I64d\n",ans-cnt);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[1000000],brr[1000000];
int main()
{
     ios::sync_with_stdio(0);
     ll b,q,l,m;
     cin>>b>>q>>l>>m;
     bool z=0,bb=0,nbb=0;
     for(int i=0;i<m;i++)
     {
          cin>>arr[i];
          if(arr[i]==0)
          z=1;
          if(arr[i]==b)
          bb=1;
          if(arr[i]==-b)
          nbb=1;
     }
     ll n=0;
     if(b<0&&q>0)
     {
          cout<<"inf";
     }
     else if(b==0)
     {
          if(z)
          cout<<"0";
          else
          cout<<"inf";
     }
     else if(q==0||q==1||q==-1)
     {
          if(q==0)
          {
               if(z)
               {
                    if(b!=0&&b<=l)
                    {
                         cout<<"1";
                    }
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
          else if(q==1)
          {
               if(b<=l&&bb==0)
               cout<<"inf";
               else
               cout<<"0";
          }
          else
          {
               if(nbb)
               {
                    if(bb==0&&b<=l)
                    cout<<"1";
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
     }
     else
     {
          while((b>=0&&b<=l)||(b<0))
          {
               n++;
               b*=q;
          }
          n--;
          q=abs(q);
          for(int i=0;i<m;i++)
          {
               if(arr[i]<=l)
               {
                    if(abs(arr[i])%abs(b)==0)
                    {
                    ll temp=arr[i]/b;

                    while(temp%q==0)
                    {
                         temp/=q;
                    }
                    if(temp==1)
                    {
                         n--;
                         cout<<i<<" ";
                    }
                    }
               }
          }
          cout<<n;
     }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[1000000],brr[1000000];
int main()
{
     ios::sync_with_stdio(0);
     ll b,q,l,m;
     cin>>b>>q>>l>>m;
     bool z=0,bb=0,nbb=0;
     for(int i=0;i<m;i++)
     {
          cin>>arr[i];
          if(arr[i]==0)
          z=1;
          if(arr[i]==b)
          bb=1;
          if(arr[i]==-b)
          nbb=1;
     }
     sort(arr, arr+m) ;
     ll n=0;
     if(abs(b)>l)
     {
          cout<<"0";
     }
     else if(b==0)
     {
          if(z)
          cout<<"0";
          else
          cout<<"inf";
     }
     else if(q==0||q==1||q==-1)
     {
          if(q==0)
          {
               if(z)
               {
                    if(b!=0)
                    {
                         cout<<"1";
                    }
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
          else if(q==1)
          {
               if(bb==0)
               cout<<"inf";
               else
               cout<<"0";
          }
          else
          {
               if(nbb)
               {
                    if(bb==0)
                    cout<<"inf";
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
     }
     else
     {
          n=1;
          while(abs(b*q)<=l)
          {
               n++;
               //cout<<b<<"\n";
               if(binary_search(arr,arr+m,b))
               {
                    n--;
                    //cout<<b<<"r ";
               }
               b*=q;
          }
          //n--;
          //q=abs(q);

          cout<<n;
     }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[1000000],brr[1000000];
int main()
{
     ios::sync_with_stdio(0);
     ll b,q,l,m;
     cin>>b>>q>>l>>m;
     bool z=0,bb=0,nbb=0;
     for(int i=0;i<m;i++)
     {
          cin>>arr[i];
          if(arr[i]==0)
          z=1;
          if(arr[i]==b)
          bb=1;
          if(arr[i]==-b)
          nbb=1;
     }
     ll n=0;
     if(b<0&&q>0)
     {
          cout<<"inf";
     }
     else if(b==0)
     {
          if(z)
          cout<<"0";
          else
          cout<<"inf";
     }
     else if(q==0||q==1||q==-1)
     {
          if(q==0)
          {
               if(z)
               {
                    if(b!=0&&b<=l)
                    {
                         cout<<"1";
                    }
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
          else if(q==1)
          {
               if(b<=l&&bb==0)
               cout<<"inf";
               else
               cout<<"0";
          }
          else
          {
               if(nbb)
               {
                    if(bb==0&&b<=l)
                    cout<<"1";
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
     }
     else
     {
          while((b>=0&&b<=l)||(b<0))
          {
               n++;
               b*=q;
          }
          n--;
          q=abs(q);
          for(int i=0;i<m;i++)
          {
               if(arr[i]<=l)
               {
                    if(abs(arr[i])%abs(b)==0)
                    {
                    ll temp=arr[i]/b;

                    while(temp%q==0)
                    {
                         temp/=q;
                    }
                    if(temp==1)
                    {
                         n--;
                         //cout<<i<<" ";
                    }
                    }
               }
          }
          cout<<n;
     }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[1000000],brr[1000000];
int main()
{
     ios::sync_with_stdio(0);
     ll b,q,l,m;
     cin>>b>>q>>l>>m;
     bool z=0,bb=0,nbb=0;
     for(int i=0;i<m;i++)
     {
          cin>>arr[i];
          if(arr[i]==0)
          z=1;
          if(arr[i]==b)
          bb=1;
          if(arr[i]==-b)
          nbb=1;
     }
     ll n=0;
     if(abs(b)>l)
     {
          cout<<"0";
     }
     else if(b==0)
     {
          if(z)
          cout<<"0";
          else
          cout<<"inf";
     }
     else if(q==0||q==1||q==-1)
     {
          if(q==0)
          {
               if(z)
               {
                    if(b!=0)
                    {
                         cout<<"1";
                    }
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
          else if(q==1)
          {
               if(bb==0)
               cout<<"inf";
               else
               cout<<"0";
          }
          else
          {
               if(nbb)
               {
                    if(bb==0&&z==0)
                    cout<<"inf";
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
     }
     else
     {
          while(abs(b)<=l)
          {
               n++;
               b*=q;
          }
          n--;
          q=abs(q);
          for(int i=0;i<m;i++)
          {
               if(arr[i]<=l)
               {
                    if(abs(arr[i])%abs(b)==0)
                    {
                    ll temp=arr[i]/b;

                    while(abs(temp)%abs(q)==0)
                    {
                         temp/=q;
                    }
                    if(temp==1)
                    {
                         n--;
                         //cout<<i<<" ";
                    }
                    }
               }
          }
          cout<<n;
     }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[1000000],brr[1000000];
int main()
{
     ios::sync_with_stdio(0);
     ll b,q,l,m;
     cin>>b>>q>>l>>m;
     bool z=0,bb=0,nbb=0;
     for(int i=0;i<m;i++)
     {
          cin>>arr[i];
          if(arr[i]==0)
          z=1;
          if(arr[i]==b)
          bb=1;
          if(arr[i]==-b)
          nbb=1;
     }
     ll n=0;
     if(abs(b)>l)
     {
          cout<<"0";
     }
     else if(b==0)
     {
          if(z)
          cout<<"0";
          else
          cout<<"inf";
     }
     else if(q==0||q==1||q==-1)
     {
          if(q==0)
          {
               if(z)
               {
                    if(b!=0)
                    {
                         cout<<"1";
                    }
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
          else if(q==1)
          {
               if(bb==0)
               cout<<"inf";
               else
               cout<<"0";
          }
          else
          {
               if(nbb)
               {
                    if(bb==0&&b<=l)
                    cout<<"1";
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
     }
     else
     {
          while(abs(b)<=l)
          {
               n++;
               b*=q;
          }

          q=abs(q);
          for(int i=0;i<m;i++)
          {
               if(arr[i]<=l)
               {
                    if(abs(arr[i])%abs(b)==0)
                    {
                    ll temp=arr[i]/b;

                    while(abs(temp)%abs(q)==0)
                    {
                         temp/=q;
                    }
                    if(temp==1)
                    {
                         n--;
                         //cout<<i<<" ";
                    }
                    }
               }
          }
          cout<<n;
     }
}


|  In English  По-русски
ankurdhir111 | Logout

HOME
CONTESTS
GYM
PROBLEMSET
GROUPS
RATING
API
RCC
VK CUP

PROBLEMSSUBMIT CODEMY SUBMISSIONSSTATUSHACKSROOMSTANDINGSCUSTOM INVOCATION

My contest submissions

#	When	Who	Problem	Lang	Verdict	Time	Memory
25928695	2017-03-29 21:04:23	ankurdhir111	C - Functions again	GNU C++	Accepted	78 ms	17700 KB
25927812	2017-03-29 21:01:35	ankurdhir111	C - Functions again	GNU C++	Wrong answer on pretest 3	15 ms	17700 KB
25924564	2017-03-29 20:47:31	ankurdhir111	C - Functions again	GNU C++	Wrong answer on pretest 9	15 ms	17700 KB
25922323	2017-03-29 20:37:19	ankurdhir111	C - Functions again	GNU C++	Wrong answer on pretest 5	15 ms	17700 KB
25918635	2017-03-29 20:20:55	ankurdhir111	B - Masha and geometric depression	GNU C++	Wrong answer on pretest 6	15 ms	17700 KB
25915949	2017-03-29 20:10:06	ankurdhir111	B - Masha and geometric depression	GNU C++	Wrong answer on pretest 4	0 ms	17700 KB
25915444	2017-03-29 20:08:08	ankurdhir111	B - Masha and geometric depression	GNU C++	Wrong answer on pretest 4	0 ms	17700 KB
25914725	2017-03-29 20:04:56	ankurdhir111	B - Masha and geometric depression	GNU C++	Wrong answer on pretest 4	0 ms	17700 KB
25914438	2017-03-29 20:03:52	ankurdhir111	B - Masha and geometric depression	GNU C++	Wrong answer on pretest 1	0 ms	17700 KB
25910315	2017-03-29 19:48:26	ankurdhir111	B - Masha and geometric depression	GNU C++	Wrong answer on pretest 4	0 ms	17700 KB
25910145	2017-03-29 19:47:49	ankurdhir111	B - Masha and geometric depression	GNU C++	Wrong answer on pretest 4	0 ms	17700 KB
25900866	2017-03-29 19:12:10	ankurdhir111	A - Anastasia and pebbles	GNU C++	Accepted	78 ms	17700 KB

Codeforces Round #407 (Div. 2)
Finished
Practice
 Add to favourites

→ Virtual participation
Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ACM-ICPC mode for virtual contests. If you've seen these problems, a virtual contest is not for you - solve these problems in the archive. If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive. Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.
Start virtual contest

→ Practice
You are registered for practice. You can solve problems unofficially. Results can be found in the contest status and in the bottom of standings.

→ Contest materials
Announcement
Tutorial

Codeforces (c) Copyright 2010-2017 Mike Mirzayanov
The only programming contests Web 2.0 platform
Server time: Mar/30/2017 06:48:18UTC+5.5 (p1).
Mobile version, switch to desktop version.
By ankurdhir111, contest: Codeforces Round #407 (Div. 2), problem: (B) Masha and geometric depression, Wrong answer on pretest 6, #
 #include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[1000000],brr[1000000];
int main()
{
     ios::sync_with_stdio(0);
     ll b,q,l,m;
     cin>>b>>q>>l>>m;
     bool z=0,bb=0,nbb=0;
     for(int i=0;i<m;i++)
     {
          cin>>arr[i];
          if(arr[i]==0)
          z=1;
          if(arr[i]==b)
          bb=1;
          if(arr[i]==-b)
          nbb=1;
     }
     sort(arr, arr+m) ;
     ll n=0;
     if(abs(b)>l)
     {
          cout<<"0";
     }
     else if(b==0)
     {
          if(z)
          cout<<"0";
          else
          cout<<"inf";
     }
     else if(q==0||q==1||q==-1)
     {
          if(q==0)
          {
               if(z)
               {
                    if(b!=0)
                    {
                         cout<<"1";
                    }
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
          else if(q==1)
          {
               if(bb==0)
               cout<<"inf";
               else
               cout<<"0";
          }
          else
          {
               if(nbb)
               {
                    if(bb==0)
                    cout<<"inf";
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
     }
     else
     {
          n=1;
          while(abs(b*q)<=l)
          {
               n++;
               //cout<<b<<"\n";
               if(binary_search(arr,arr+m,b))
               {
                    n--;
                    //cout<<b<<"r ";
               }
               b*=q;
          }
          //n--;
          //q=abs(q);

          cout<<n;
     }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[1000000],brr[1000000];
int main()
{
     ios::sync_with_stdio(0);
     ll b,q,l,m;
     cin>>b>>q>>l>>m;
     bool z=0,bb=0,nbb=0;
     for(int i=0;i<m;i++)
     {
          cin>>arr[i];
          if(arr[i]==0)
          z=1;
          if(arr[i]==b)
          bb=1;
          if(arr[i]==-b)
          nbb=1;
     }
     ll n=0;
     if(abs(b)>l)
     {
          cout<<"0";
     }
     else if(b==0)
     {
          if(z)
          cout<<"0";
          else
          cout<<"inf";
     }
     else if(q==0||q==1||q==-1)
     {
          if(q==0)
          {
               if(z)
               {
                    if(b!=0)
                    {
                         cout<<"1";
                    }
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
          else if(q==1)
          {
               if(bb==0)
               cout<<"inf";
               else
               cout<<"0";
          }
          else
          {
               if(nbb)
               {
                    if(bb==0&&b<=l)
                    cout<<"1";
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
     }
     else
     {
          while(abs(b)<=l)
          {
               n++;
               b*=q;
          }
          n--;
          q=abs(q);
          for(int i=0;i<m;i++)
          {
               if(arr[i]<=l)
               {
                    if(abs(arr[i])%abs(b)==0)
                    {
                    ll temp=arr[i]/b;

                    while(abs(temp)%abs(q)==0)
                    {
                         temp/=q;
                    }
                    if(temp==1)
                    {
                         n--;
                         //cout<<i<<" ";
                    }
                    }
               }
          }
          cout<<n;
     }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[1000000],brr[1000000];
int main()
{
     ios::sync_with_stdio(0);
     ll b,q,l,m;
     cin>>b>>q>>l>>m;
     bool z=0,bb=0,nbb=0;
     for(int i=0;i<m;i++)
     {
          cin>>arr[i];
          if(arr[i]==0)
          z=1;
          if(arr[i]==b)
          bb=1;
          if(arr[i]==-b)
          nbb=1;
     }
     ll n=0;
     if(abs(b)>l)
     {
          cout<<"0";
     }
     else if(b==0)
     {
          if(z)
          cout<<"0";
          else
          cout<<"inf";
     }
     else if(q==0||q==1||q==-1)
     {
          if(q==0)
          {
               if(z)
               {
                    if(b!=0)
                    {
                         cout<<"1";
                    }
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
          else if(q==1)
          {
               if(bb==0)
               cout<<"inf";
               else
               cout<<"0";
          }
          else
          {
               if(nbb)
               {
                    if(bb==0)
                    cout<<"inf";
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
     }
     else
     {
          while(abs(b)<=l)
          {
               n++;
               b*=q;
          }
          n--;
          //q=abs(q);
          for(int i=0;i<m;i++)
          {
               if(arr[i]<=l)
               {
                    if(abs(arr[i])%abs(b)==0)
                    {
                    ll temp=arr[i]/b;

                    while(abs(temp)%abs(q)==0)
                    {
                         temp/=q;
                    }
                    if(temp==1)
                    {
                         n--;
                         //cout<<i<<" ";
                    }
                    }
               }
          }
          cout<<n;
     }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[1000000],brr[1000000];
int main()
{
     ios::sync_with_stdio(0);
     ll b,q,l,m;
     cin>>b>>q>>l>>m;
     bool z=0,bb=0,nbb=0;
     for(int i=0;i<m;i++)
     {
          cin>>arr[i];
          if(arr[i]==0)
          z=1;
          if(arr[i]==b)
          bb=1;
          if(arr[i]==-b)
          nbb=1;
     }
     sort(arr, arr+m) ;
     ll n=0;
     if(abs(b)>l)
     {
          cout<<"0";
     }
     else if(b==0)
     {
          if(z)
          cout<<"0";
          else
          cout<<"inf";
     }
     else if(q==0||q==1||q==-1)
     {
          if(q==0)
          {
               if(z)
               {
                    if(b!=0&&bb==0)
                    {
                         cout<<"1";
                    }
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
          else if(q==1)
          {
               if(bb==0)
               cout<<"inf";
               else
               cout<<"0";
          }
          else
          {
               if(nbb)
               {
                    if(bb==0)
                    cout<<"inf";
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
     }
     else
     {
          n=0;
          while(abs(b)<=l)
          {
               n++;
               //cout<<b<<"\n";
               if(binary_search(arr,arr+m,b))
               {
                    n--;
                    //cout<<b<<"r ";
               }
               b*=q;
          }
          //n--;
          //q=abs(q);

          cout<<n;
     }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[1000000],brr[1000000];
int main()
{
     ios::sync_with_stdio(0);
     ll b,q,l,m;
     cin>>b>>q>>l>>m;
     bool z=0,bb=0,nbb=0;
     for(int i=0;i<m;i++)
     {
          cin>>arr[i];
          if(arr[i]==0)
          z=1;
          if(arr[i]==b)
          bb=1;
          if(arr[i]==-b)
          nbb=1;
     }
     sort(arr, arr+m) ;
     ll n=0;
     if(abs(b)>l)
     {
          cout<<"0";
     }
     else if(b==0)
     {
          if(z)
          cout<<"0";
          else
          cout<<"inf";
     }
     else if(q==0||q==1||q==-1)
     {
          if(q==0)
          {
               if(z)
               {
                    if(b!=0)
                    {
                         cout<<"1";
                    }
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
          else if(q==1)
          {
               if(bb==0)
               cout<<"inf";
               else
               cout<<"0";
          }
          else
          {
               if(nbb)
               {
                    if(bb==0)
                    cout<<"inf";
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
     }
     else
     {
          n=0;
          while(abs(b)<=l)
          {
               n++;
               //cout<<b<<"\n";
               if(binary_search(arr,arr+m,b))
               {
                    n--;
                    //cout<<b<<"r ";
               }
               b*=q;
          }
          //n--;
          //q=abs(q);

          cout<<n;
     }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[1000000],brr[1000000];
int main()
{
     ios::sync_with_stdio(0);
     ll b,q,l,m;
     cin>>b>>q>>l>>m;
     bool z=0,bb=0,nbb=0;
     for(int i=0;i<m;i++)
     {
          cin>>arr[i];
          if(arr[i]==0)
          z=1;
          if(arr[i]==b)
          bb=1;
          if(arr[i]==-b)
          nbb=1;
     }
     ll n=0;
     if(abs(b)>l)
     {
          cout<<"0";
     }
     else if(b==0)
     {
          if(z)
          cout<<"0";
          else
          cout<<"inf";
     }
     else if(q==0||q==1||q==-1)
     {
          if(q==0)
          {
               if(z)
               {
                    if(b!=0)
                    {
                         cout<<"1";
                    }
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
          else if(q==1)
          {
               if(bb==0)
               cout<<"inf";
               else
               cout<<"0";
          }
          else
          {
               if(nbb)
               {
                    if(bb==0)
                    cout<<"inf";
                    else
                    cout<<"0";
               }
               else
               {
                    cout<<"inf";
               }
          }
     }
     else
     {
          n=1;
          while(abs(b*q)<=l)
          {
               n++;
               //cout<<b<<"\n";
               if(binary_search(arr,arr+m,b))
               {
                    n--;
                    //cout<<b<<"r ";
               }
               b*=q;
          }
          //n--;
          //q=abs(q);

          cout<<n;
     }
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
const int maxn = 1e4 + 10;
double abs(double mm)
{
   if(mm < 0.0)
        mm = -mm;
   return mm;
}
int main()
{
	int b,q,l,m;
	scanf("%d%d%d%d",&b,&q,&l,&m);
	set<int > S;
	S.clear();
	for(int i = 0; i < m; i++)
    {
        int x;
        scanf("%d",&x);
        S.insert(x);
    }
	if(q == 0)
    {
         if((S.find(b) == S.end() && S.find(0) != S.end() && abs(b) <= l))
                printf("1\n");
         else if(S.find(b) != S.end() && S.find(0) != S.end())
            printf("0\n");
         else
            printf("inf\n");
    }
    else if(abs(q) == 1)
    {
        if(q == 1)
        {
            if(S.find(b) == S.end() && abs(b) <= l)
                printf("inf\n");
            else
                printf("0\n");
        }
        else
        {
             if((S.find(b) != S.end() && S.find(-b) == S.end() && abs(b) <= l) || (S.find(-b) != S.end() && S.find(b) == S.end() && abs(b) <= l))
                printf("1\n");
             else if(S.find(b) != S.end() && S.find(-b) != S.end() && abs(b) <= l)
                printf("0\n");
             else if(S.find(b) == S.end() && S.find(-b) == S.end() && abs(b) <= l)
                printf("2\n");
             else
                printf("inf\n");
        }
    }
    else
    {
        int ans = 0;
        while(abs(b) <= l)
        {
            if(S.find(b) == S.end())
                ans++;//cout << ans++ << endl;
            b = b * q;
            //cout << b << " " << ans << endl;
        }
        printf("%d\n",ans);
    }
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
const int maxn = 1e4 + 10;
double abs(double mm)
{
   if(mm < 0.0)
        mm = -mm;
   return mm;
}
int main()
{
	int b,q,l,m;
	scanf("%d%d%d%d",&b,&q,&l,&m);
	set<int > S;
	S.clear();
	for(int i = 0; i < m; i++)
    {
        int x;
        scanf("%d",&x);
        S.insert(x);
    }
	if(q == 0)
    {
         if((S.find(b) == S.end() && S.find(0) != S.end() && abs(b) <= l))
                printf("1\n");
         else if((S.find(b) != S.end() && S.find(0) != S.end()) || abs(b) > l)
            printf("0\n");
         else
            printf("inf\n");
    }
    else if(abs(q) == 1)
    {
        if(q == 1)
        {
            if(S.find(b) == S.end() && abs(b) <= l)
                printf("inf\n");
            else
                printf("0\n");
        }
        else
        {
             if((S.find(b) == S.end() && abs(b) <= l) || (S.find(-b) == S.end() && abs(b) <= l))
                printf("inf\n");
             else
                printf("0\n");
        }
    }
    else
    {
        if(b == 0)
        {
            if(S.find(0) == S.end())
                printf("0\n");
            else
                printf("1\n");
        }
        else{
            int ans = 0;
            while(abs(b) <= l)
            {
                if(S.find(b) == S.end())
                    ans++;//cout << ans++ << endl;
                b = b * q;
                //cout << b << " " << ans << endl;
            }
            printf("%d\n",ans);
        }

    }
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
const int maxn = 1e4 + 10;
double abs(double mm)
{
   if(mm < 0.0)
        mm = -mm;
   return mm;
}
int main()
{
	int b,q,l,m;
	scanf("%d%d%d%d",&b,&q,&l,&m);
	set<int > S;
	S.clear();
	for(int i = 0; i < m; i++)
    {
        int x;
        scanf("%d",&x);
        S.insert(x);
    }
	if(q == 0)
    {
         if((S.find(b) == S.end() && S.find(0) != S.end() && abs(b) <= l))
                printf("1\n");
         else if((S.find(b) != S.end() && S.find(0) != S.end()) || abs(b) > l)
            printf("0\n");
         else
            printf("inf\n");
    }
    else if(abs(q) == 1)
    {
        if(q == 1)
        {
            if(S.find(b) == S.end() && abs(b) <= l)
                printf("inf\n");
            else
                printf("0\n");
        }
        else
        {
             if((S.find(b) == S.end() && abs(b) <= l) || (S.find(-b) == S.end() && abs(b) <= l))
                printf("inf\n");
             else
                printf("0\n");
        }
    }
    else
    {
        if(b == 0)
        {
            if(S.find(0) == S.end())
                printf("inf\n");
            else
                printf("0\n");
        }
        else{
            int ans = 0;
            while(abs(b) <= l)
            {
                if(S.find(b) == S.end())
                    ans++;//cout << ans++ << endl;
                b = b * q;
                //cout << b << " " << ans << endl;
            }
            printf("%d\n",ans);
        }

    }
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
const int maxn = 1e4 + 10;
double abs(double mm)
{
   if(mm < 0.0)
        mm = -mm;
   return mm;
}
int main()
{
	int b,q,l,m;
	scanf("%d%d%d%d",&b,&q,&l,&m);
	set<int > S;
	S.clear();
	for(int i = 0; i < m; i++)
    {
        int x;
        scanf("%d",&x);
        S.insert(x);
    }
	if(q == 0)
    {
         if((S.find(b) == S.end() && S.find(0) != S.end() && abs(b) <= l))
                printf("1\n");
         else if(S.find(b) != S.end() && S.find(0) != S.end())
            printf("0\n");
         else
            printf("inf\n");
    }
    else if(abs(q) == 1)
    {
        if(q == 1)
        {
            if(S.find(b) == S.end() && abs(b) <= l)
                printf("inf\n");
            else
                printf("0\n");
        }
        else
        {
             if((S.find(b) == S.end() && abs(b) <= l) || (S.find(-b) == S.end() && abs(b) <= l))
                printf("inf\n");
             else
                printf("0\n");
        }
    }
    else
    {
        int ans = 0;
        while(abs(b) <= l)
        {
            if(S.find(b) == S.end())
                ans++;//cout << ans++ << endl;
            b = b * q;
            //cout << b << " " << ans << endl;
        }
        printf("%d\n",ans);
    }
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
const int maxn = 1e4 + 10;
double abs(double mm)
{
   if(mm < 0.0)
        mm = -mm;
   return mm;
}
int main()
{
	int b,q,l,m;
	scanf("%d%d%d%d",&b,&q,&l,&m);
	set<int > S;
	S.clear();
	for(int i = 0; i < m; i++)
    {
        int x;
        scanf("%d",&x);
        S.insert(x);
    }
	if(q == 0)
    {
         if((S.find(b) == S.end() && S.find(0) != S.end() && abs(b) <= l))
                printf("1\n");
         else if((S.find(b) != S.end() && S.find(0) != S.end()) || abs(b) > l)
            printf("0\n");
         else
            printf("inf\n");
    }
    else if(abs(q) == 1)
    {
        if(q == 1)
        {
            if(S.find(b) == S.end() && abs(b) <= l)
                printf("inf\n");
            else
                printf("0\n");
        }
        else
        {
             if((S.find(b) == S.end() && abs(b) <= l) || (S.find(-b) == S.end() && abs(b) <= l))
                printf("inf\n");
             else
                printf("0\n");
        }
    }
    else
    {
        int ans = 0;
        while(abs(b) <= l)
        {
            if(S.find(b) == S.end())
                ans++;//cout << ans++ << endl;
            b = b * q;
            //cout << b << " " << ans << endl;
        }
        printf("%d\n",ans);
    }
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
const int maxn = 1e4 + 10;
int main()
{
	int q,l,m;
	__int64 b;
	scanf("%I64d%d%d%d",&b,&q,&l,&m);
	set<__int64 > S;
	S.clear();
	for(int i = 0; i < m; i++)
    {
        int x;
        scanf("%d",&x);
        S.insert(x);
    }
	if(q == 0)
    {
         if((S.find(b) == S.end() && S.find(0) != S.end() && abs(b) <= l))
                printf("1\n");
         else if((S.find(b) != S.end() && S.find((__int64)0) != S.end()) || abs(b) > l)
            printf("0\n");
         else
            printf("inf\n");
    }
    else if(abs(q) == 1)
    {
        if(q == 1)
        {
            if(S.find(b) == S.end() && abs(b) <= l)
                printf("inf\n");
            else
                printf("0\n");
        }
        else
        {
             if((S.find(b) == S.end() && abs(b) <= l) || (S.find(-b) == S.end() && abs(b) <= l))
                printf("inf\n");
             else
                printf("0\n");
        }
    }
    else
    {
        if(b == 0)
        {
            if(S.find(0) == S.end())
                printf("inf\n");
            else
                printf("0\n");
        }
        else{
            int ans = 0;
            while(abs(b) <= l)
            {
                if(S.find(b) == S.end())
                    ans++;//cout << ans++ << endl;
                b = b * q;
                //cout << b << " " << ans << endl;
            }
            printf("%d\n",ans);
        }

    }
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
const int maxn = 1e4 + 10;
double abs(double mm)
{
   if(mm < 0.0)
        mm = -mm;
   return mm;
}
int main()
{
	int b,q,l,m;
	scanf("%d%d%d%d",&b,&q,&l,&m);
	set<int > S;
	S.clear();
	for(int i = 0; i < m; i++)
    {
        int x;
        scanf("%d",&x);
        S.insert(x);
    }
	if(q == 0)
        return 0;
    else if(abs(q) == 1)
    {
        if(q == 1)
        {
            if(S.find(b) == S.end() && abs(b) <= l)
                printf("inf\n");
            else
                printf("0\n");
        }
        else
        {
             if((S.find(b) != S.end() && S.find(-b) == S.end() && abs(b) <= l) || (S.find(-b) != S.end() && S.find(b) == S.end() && abs(b) <= l))
                printf("1\n");
             else if(S.find(b) != S.end() && S.find(-b) != S.end() && abs(b) <= l)
                printf("0\n");
             else if(S.find(b) == S.end() && S.find(-b) == S.end() && abs(b) <= l)
                printf("2\n");
             else
                printf("inf\n");
        }
    }
    else
    {
        int ans = 0;
        while(abs(b) <= l)
        {
            if(S.find(b) == S.end())
                ans++;//cout << ans++ << endl;
            b = b * q;
            //cout << b << " " << ans << endl;
        }
        printf("%d\n",ans);
    }
	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
const int maxn = 1e4 + 10;
double abs(double mm)
{
   if(mm < 0.0)
        mm = -mm;
   return mm;
}
int main()
{
	int b,q,l,m;
	scanf("%d%d%d%d",&b,&q,&l,&m);
	set<int > S;
	S.clear();
	for(int i = 0; i < m; i++)
    {
        int x;
        scanf("%d",&x);
        S.insert(x);
    }
	if(q == 0)
    {
         if((S.find(b) == S.end() && S.find(0) != S.end() && abs(b) <= l))
                printf("1\n");
         else if((S.find(b) != S.end() && S.find(0) != S.end()) || abs(b) > l)
            printf("0\n");
         else
            printf("inf\n");
    }
    else if(abs(q) == 1)
    {
        if(q == 1)
        {
            if(S.find(b) == S.end() && abs(b) <= l)
                printf("inf\n");
            else
                printf("0\n");
        }
        else
        {
             if((S.find(b) == S.end() && abs(b) <= l) || (S.find(-b) == S.end() && abs(b) <= l))
                printf("inf\n");
             else
                printf("0\n");
        }
    }
    else
    {
        if(b == 0)
        {
            if(S.find(0) == S.end())
                printf("1\n");
            else
                printf("inf\n");
        }
        else{
            int ans = 0;
            while(abs(b) <= l)
            {
                if(S.find(b) == S.end())
                    ans++;//cout << ans++ << endl;
                b = b * q;
                //cout << b << " " << ans << endl;
            }
            printf("%d\n",ans);
        }

    }
	return 0;
}