Problem:
Unable Count
I would, if I could,
If I couldn't how could I?
I couldn't, without I could, could I?
Could you, without you could, could ye?
Could ye? could ye?
Could you, without you could, could ye?
It is true, as this old rhyme says, that we can only DO what
we can DO and we cannot DO what we cannot DO. Changing some of
DOs with COUNTs, we have another statement that we can only COUNT
what we can DO and we cannot COUNT what we cannot DO, which looks
rather false. We could count what we could do as well as we could
count what we couldn't do.  Couldn't we, if we confine ourselves
to finite issues?
Surely we can count, in principle, both what we can do and
what we cannot do, if the object space is finite. Yet, sometimes
we cannot count in practice what we can do or what we cannot do.
Here, you are challenged, in a set of all positive integers up
to (and including) a given bound
n
, to count
all the integers that cannot be represented by a formula of
the form
a
*
i
+
b
*
j
, where
a
and
b
are given positive integers and
i
and
j
are variables ranging over non-negative integers. You are requested
to report only the result of the count, i.e. how many integers
are not representable.
For example, given
n
= 7,
a
= 2,
b
= 5,
you should answer 2, since 1 and 3 cannot be represented in a
specified form, and the other five numbers are representable as follows:
2 = 2*1 + 5*0,    4 = 2*2 + 5*0,    5 = 2*0 + 5*1,
   6 = 2*3 + 5*0,    7 = 2*1 + 5*1.
Input
The input is a sequence of lines. Each line consists of three integers,
n, a
and
b,
in this order,
separated by a
space
.
The integers
n
,
a
and
b
are
all positive and at most one million, except those in the last
line. The last line consists of three zeros.
Output
For each input line except the last one, your program should
write out a line that contains only the result of the count.
Sample Input
10 2 3
10 2 5
100 5 25
0 0 0
Output for the Sample Input
1
2
80

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,l,r) for(ll i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(A) A.begin(),A.end()
int main(){
    while(1){
        int n,a,b;cin>>n>>a>>b;
        if(!n)return 0;
        vector<bool>dp(n+1);
        dp[0]=1;
        REP(i,n+1){
            if(i>=a&&dp[i-a])dp[i]=1;
            if(i>=b&&dp[i-b])dp[i]=1;
        }
        cout<<count(ALL(dp),0)<<endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3316
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1e18 + 10
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b; 
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  while(1){
    int n,a,b;
    cin>>n>>a>>b;
    if(n==0) break;
    if(a>b) swap(a,b);
    vector<int> v(a,0);
    int ans=0;
    v[0]=1;
    rep(i,n){
      //rep(j,a) cout<<v[j]<<" ";
      //cout<<endl;
      int num=i+1;
      if(num%b==0){
	v[num%a]=1;
      }
      if(v[num%a]==0){
	ans++;
      }
      
    }
    cout<<ans<<endl;
  }

  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3144
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;

void solve(int n, int a, int b) {
  vector< int > reps(n + 1, 1);
  queue< int > que;

  reps[0] = 0;
  que.emplace(0);

  while (not que.empty()) {
    int v = que.front();
    que.pop();

    if (v + a <= n and reps[v + a]) {
      reps[v + a] = 0;
      que.emplace(v + a);
    }
    if (v + b <= n and reps[v + b]) {
      reps[v + b] = 0;
      que.emplace(v + b);
    }
  }

  cout << accumulate(reps.begin(), reps.end(), 0) << endl;
}

int main() {
  int n, a, b;
  
  while (cin >> n >> a >> b, n) {
    solve(n, a, b);
  }
}
accuracy: 1
time_ms: 10
memory_kb: 7084
final_rank: 17

code_snippet: #include<iostream>

using namespace std;

bool Judge(int m,int a,int b)
{
	int v = 0;
	while (v * a <= m)
	{
		if ((m - v * a) % b == 0)
			return true;
		v++;
	}

	return false;
}

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	while (n != 0 && a != 0 && b != 0)
	{
		bool* ok = new bool[n + 1];
		fill(ok, ok + n + 1, false);
		for (int i = 1; i <= n; i++)
		{
			if (ok[i]) continue;
			if (Judge(i, a, b))
			{
				ok[i] = true;
				for (int j = 2; i * j <= n; j++)
					ok[i * j] = true;
			}
		}
		int ans = 0;
		for (int i = 1; i <= n; i++)
			ans += (!ok[i]);
		cout << ans << endl;

		cin >> n >> a >> b;
	}

	//system("pause");
}
accuracy: 1
time_ms: 520
memory_kb: 7100
final_rank: 20

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
    while(1){
        lli n,a,b;
        cin >> n >> a >> b;
        if(n == 0) break;

        vector<bool> table(n+1, false);
        table[0] = true;
        int ans = 0;
        for(int i=0; i<=n; i++){
            if(!table[i]){
                ans++;
                continue;
            }
            if(i+a <= n) table[i+a] = true;
            if(i+b <= n) table[i+b] = true;
        }
        cout << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3196
final_rank: 8

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;


int main() {
	while (true) {
		int N,A,B;cin>>N>>A>>B;
		if(!N)break;
		vector<int>oks(1e6+1);
		oks[0]=true;
		for (int i = 0; i < 1e6; ++i) {
			if (oks[i]) {
				if (i + A <= 1e6) {
					oks[i+A]=true;
				}
				if (i + B <= 1e6) {
					oks[i+B]=true;
				}
			}
		}
		int ans=N-accumulate(oks.begin(),oks.begin()+N+1,0)+1;
		cout<<ans<<endl;
	}
	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 6968
final_rank: 18

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>

using namespace std;

bool* checkTable;

void func(int N,int a, int b){

	int count = 0,a_limit;

	a_limit = N/a;

	for(int i = 1; i <= a_limit; i++){
		checkTable[a*i] = true;
	}
	for(int i = b; i <= N; i++){
		if(i % b == 0 || checkTable[i-b] == true){
			checkTable[i] = true;
		}
	}


	for(int i = 1; i <= N; i++){
		if(checkTable[i] == false)count++;
	}

	printf("%d\n",count);

}

int main(){

	int N,a,b;
	checkTable = new bool[1000001];

	while(true){
		scanf("%d %d %d",&N,&a,&b);
		if(N == 0 && a == 0 && b == 0)break;

		for(int i =1; i <= N; i++)checkTable[i] = false;

		func(N,a,b);
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3652
final_rank: 11

code_snippet: #include<iostream>
using namespace std;
int n, a[2];
int dp[2000000];
int main() {
	while (true) {
		cin >> n >> a[0] >> a[1];
		if (n == 0) { break; }
		for (int i = 0; i < 2000000; i++)dp[i] = 0;
		dp[0] = 1;
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 1000000; j++) {
				if (dp[j] == 0) { continue; }
				dp[j + a[i]] = 1;
			}
		}
		int sum = 0;
		for (int i = 1; i <= n; i++) {
			if (dp[i] == 0)sum += 1;
		}
		cout << sum << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 8972
final_rank: 19

code_snippet: #include <iostream>
#include <algorithm>

using namespace std;

int main(){

  int n,a,b,count=0,i,j;
  
  cin >> n >> a >> b;
  while(n!=0){
    count = n;
    if(a<b) swap(a,b);
    int ar[1000010]={};
    ar[a]=1;
    ar[b]=1;
    for(i=1;i<=n;i++){
      if(i-a>0)
	if(ar[i-a]==1) ar[i] = 1;
      if(i-b>0)
	if(ar[i-b]==1) ar[i] = 1;
      count -= ar[i];
    }
    cout << count << endl;
    cin >> n >> a >> b;
  }
  
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 5072
final_rank: 14

code_snippet: #include <iostream>
#include <vector>
#include <string.h>

using namespace std;
static const int SIZE = 1000001;
int dp[SIZE];

void solve()
{
	long long int n, a, b;
	while (cin >> n >> a >> b, n || a || b)
	{
		memset(dp, 0, sizeof(dp));
		dp[0] = 1;
		for (int i = 0; i <= n; ++i)
		{
			if (dp[i] == 1)
			{
				if (i + a <= n)
				{
					dp[i + a] = 1;
				}
				if (i + b <= n)
				{
					dp[i + b] = 1;
				}
			}
		}
		int ans = 0;
		for (int i = 1; i <= n; ++i)
		{
			if (dp[i] == 0)
			{
				++ans;
			}
		}
		cout << ans << endl;
	}
}

int main()
{
	solve();
	return(0);
}
accuracy: 1
time_ms: 10
memory_kb: 5076
final_rank: 12

code_snippet: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

bool checker[2000000];

int main(){
	int n, a, b;
	while(true){
		cin >> n >> a >> b;
		if(n == 0 && a == 0 && b == 0){
			break;
		}
		for(int i = 0; i <= n; i++){
			checker[i] = false;
		}
		checker[0] = true;
		for(int i = 1; i <= n; i++){
			if(i - a >= 0){
				if(checker[i - a]){
					checker[i] = true;
					continue;
				}
			}
			if(i - b >= 0){
				if(checker[i - b]){
					checker[i] = true;
					continue;
				}
			}
		}
		int count = 0;
		for(int i = 0; i <= n; i++){
			if(!checker[i]){
				count++;
			}
		}
		printf("%d\n", count);
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 2120
final_rank: 4

code_snippet: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int a,b,c;
	while(cin>>a>>b>>c,a+b+c){
		vector<bool>in(a+1);
		in[0]=true;
		if(b>c)swap(b,c);
		rep(i,a+1){
			if(i-b<0)continue;
			if(in[i-b])in[i]=true;;
			if(i-c<0)continue;
			if(in[i-c])in[i]=true;;
		}
		int co=0;
		loop(i,1,a+1)if(!in[i])co++;
		cout<<co<<endl;
	}
}
accuracy: 1
time_ms: 20
memory_kb: 1316
final_rank: 1

code_snippet: #include <cstdio>
#include <cstring>
int n,a,b;
int dp[1500001];
int main(void){
	while(1){
		scanf("%d %d %d",&n,&a,&b);
		if(n+a+b==0)break;
		memset(dp,0,sizeof(dp));
		dp[0]=1;
		int cnt=-1;
		for(int i=0;i<=n;i++){
			if(dp[i]>0){
				cnt++;
				dp[i+a]=dp[i];
				dp[i+b]=dp[i];
			}
		}
		printf("%d\n",n-cnt);
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 6892
final_rank: 16

code_snippet: #include<iostream>
#include<cstdio>
#include<set>
#include<map>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cassert>
#include<string>
#include<vector>
#include<queue>
#define MAX_N 1000010
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 100000005
#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;
typedef long long int ll;
typedef pair<int,int> PI;

int gcm(int a,int b){
    if(a<b){swap(a,b);}
    while(b>0){
        a%=b;
        swap(a,b);
    }
    return a;
}

int lcm(int a,int b){
    return a/gcm(a,b)*b;
}

int main(){
    int n,a,b;
    int LCM,GCM;
    bool flag[MAX_N];
    int count[MAX_N];
    while(1){
        cin>>n>>a>>b;
        if(n==0)
            break;
        rep(i,MAX_N){
            flag[i]=0;
        }
        LCM=lcm(a,b);
        GCM=gcm(a,b);
        int ans;
        int irange = min(MAX_N-1,LCM)/a+1;
        rep(i,irange){
            int jrange =(min(MAX_N-1,LCM)-a*i)/b+1;
            rep(j,jrange){flag[a*i+b*j]=true;}
        }
        count[0]=0;
        rep(i,MAX_N-1){
            count[i+1]=count[i]+flag[i+1];
        }
        if(n<LCM){
            ans=count[n];
        }
        else{
            ans=count[LCM]+(n-LCM)/GCM;
        }
        cout<<n-ans<<endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 6040
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long int uli;

uli xgcd(uli a,uli b,uli &x,uli &y){
   if(b==0){
      x=1,y=0;
      return a;
   }
   uli x1,y1;
   uli g=xgcd(b,a%b,x1,y1);
   x=y1;
   y=x1-(a/b)*y1;
   return g;
}
int main(){
   uli n,a,b,x,y;
   while(scanf("%lld %lld %lld",&n,&a,&b)==3){
      if(n==0 && a==0 && b==0)break;
      uli g=xgcd(a,b,x,y);
      uli ans=0;
      for(uli v=g;v<=n;v+=g){
         uli k=v/g;
         uli xx=k*x,yy=k*y;
         uli r=(xx*g)/b;
         if(xx<0 && (-xx*g)%b!=0)r--;
         if(-yy*g<=a*r){
            ans++;
         }
      }
      printf("%lld\n",n-ans);
   }
   return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 1188
final_rank: 6

code_snippet: #include <iostream>
#include <vector>

using namespace std;

int main() {
	int n, a, b;
	while ( cin >> n >> a >> b, n || a || b ) {
		vector<bool> f(n+1, false); f[0] = true;
		int x[2] = {a, b};
		for (int i = 0; i < 2; ++i) {
			for (int j = 0; j < n+1; ++j) {
				if (f[j] && j+x[i] < n+1) {
					f[j+x[i]] = true;
				}
			}
		}

		int ans = 0;
		for (int i = 1; i < f.size(); ++i) {
			if (f[i]) ++ans;
		}
		cout << n-ans << endl;
	}
}
accuracy: 1
time_ms: 30
memory_kb: 1316
final_rank: 2

code_snippet: /* ***********************************************
Author        :axp
Created Time  :2015/5/15 23:46:43
File Name     :1.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;

const int maxn = 1000010;
int ans;
int n,a,b;
bool v[maxn<<1];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    while(cin>>n>>a>>b && n)
	{
		memset(v,0,sizeof(v));
		ans=0;
		v[0]=1;
		for(int i=0;i<=n;i++)
			if(v[i])
				v[i+a]=v[i+b]=1;
			else
				ans++;
		cout<<ans<<endl;
	}
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3120
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

int a, b, n;

int main()
{
  while((cin >> n >> a >> b) && n){
    int res = n;
    bool* ok = new bool[n + 1];
    rep(i, n + 1) ok[i] = false;

    rep(i, n / a + 1) ok[i * a] = true;
    //rep(i, n / a + 1) if(ok[i]) for(int j = i + b; j <= n; j += b) ok[j] = true;
    rep(i, n + 1) if(ok[i] && i + b <= n) ok[i + b] = true;

    rrep(i, 1, n + 1) if(ok[i]) res -= 1;
    cout << res << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 5156
final_rank: 13

code_snippet: #include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <map>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define SUPmaxp 1000001

bool bs[SUPmaxp];
int maxp,a,b;

int main(){
	while(true){
		cin>>maxp>>a>>b;			if(!maxp) return 0;
		FOR(p,0,maxp+1) bs[p]=false;
		bs[0]=true;
		FOR(p,0,maxp+1) if(bs[p]){
			if(p+a<=maxp) bs[p+a]=true;
			if(p+b<=maxp) bs[p+b]=true;
		}
		int re=0;
		FOR(p,1,maxp+1) if(!bs[p]) re++;
		cout<<re<<endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 2136
final_rank: 5

code_snippet: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int main() {
  int n, a, b;
  while(cin >>n >>a >>b && n){
    vector<bool> v(n + 5, false);
    for(int i = a; i < v.size(); i += a) v[i] = true;
    for(int i = b; i < v.size(); ++i) if(i % b == 0 || v[i - b]) v[i] = true;
    int cnt = 0;
    FOR(i, 1, n + 1) if(!v[i]) ++cnt;
    cout <<cnt <<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 1316
final_rank: 2