Photolog

Through the Looking-Glass
2010-10-12: Through the Looking-Glass
My radio speaks is binary!
2010-10-10: My radio speaks is binary!
Gigaminx: (present for my birthday)
2010-09-16: Gigaminx: (present for my birthday)
Trini on bike
2010-09-05: Trini on bike
Valporquero
2010-08-28: Valporquero
My new bike!
2010-08-22: My new bike!
Mario and Ana's wedding
2010-08-13: Mario and Ana's wedding
Canyoning in Guara
2010-08-07: Canyoning in Guara
Trini and Mari in Marbella
2010-08-05: Trini and Mari in Marbella
Trini and Chelo in Tabarca
2010-08-03: Trini and Chelo in Tabarca
Valid XHTML 1.1
Log in
Back to list of problems

Power Crisis

151.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int num;
int nums[100];

void compute(void)
{
	int i,j,k;

	for(i=1; i<=num; i++) {
		int last=1;
		nums[1]=0;
		for(j=2; j<=num; j++) {
			nums[j]=1;
		}
		while(1) {
			int done=1;
			for(j=1; j<=num; j++) {
				if (nums[j]) {
					done=0;
					break;
				}
			}
			if (last==13) {
				if (done) {
					printf("%d\n", i);
					return;
				} else {
					break;
				}
			}
			for(k=0; k<i; k++) {
				while(1) {
					last++;
					if (last>num) {
						last=1;
					}
					if (nums[last]) {
						break;
					}
				}
			}
			nums[last]=0;
		}
	}
	printf("Ein?\n");
}

int
main(void)
{
	while(fscanf(stdin, "%d", &num)==1) {
		if (num==0) {
			exit(0);
		}
		compute();
	}
	exit(0);
}