View Code of Problem 80

int a[100001] = {0};
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    while(cin>>n&&n!=0){
        for(int i=1; i<=n; i++){
            a[i] = 1;
        }
        int c = n;
        int cnt =0;
        while(c!=1){
            for(int i =1; i<=n; i++){
                if(a[i]){
                    cnt++;
                    if(cnt==3){
                        cnt = 0;
                        a[i]=0;
                        c--;
                    }
                }
            }
        }
        for(int i = 1; i<=n; i++){
            if(a[i]==1){
                cout<<i<<endl;
            }
        }

    }
    return 0;
}

Double click to view unformatted code.


Back to problem 80