U E D R , A S I H C RSS

Ones/송지원

문제 설명

링크 http://poj.org/problem?id=2551
개요
입력
출력

Status

Run ID User Problem Result Memory Time Language Code Length
9255717 enochbible 2551 Time Limit Exceeded C 1263B
9255761 enochbible 2551 Accepted 184K 641MS C 1024B


Source Code

#include <stdio.h>
#define LENBOUND 10000
#define ARRBOUND 2500 // LENBOUND/4

typedef struct longint {
	int length;
	int digits[ARRBOUND]; // 0000~9999
} longint;

void ones( longint *pns, int len )
{
	int i;
	int j;
	pns->length = len;
	for( i = 0; i < ARRBOUND; i++ )
		pns->digits[i] = 0;
	j = ARRBOUND - 1;
	while( len >= 4 ) {
		pns->digits[j] = 1111;
		len -= 4;
		j--;
	}

	switch(len) {
		case 1:
		pns->digits[j] = 1;
		break;
		case 2:
		pns->digits[j] = 11;
		break;
		case 3:
		pns->digits[j] = 111;
		break;
	}
}

int division( longint *pns, int divisor ) {
	int i = ARRBOUND - (pns->length + 3) / 4;
	int rem = 0;
	for( ; i < ARRBOUND; i++ )	{
		pns->digits[i] += (rem * 10000);
		rem = pns->digits[i] % divisor;
	}
	return rem;
}

void main() {
	longint ns;
	int n;
	while( scanf("%d", &n) != EOF )	{
		int i;
		for( i = 1; i <= LENBOUND; i++ ) {
			ones(&ns, i);
			if( division(&ns, n) == 0 ) break;
		}
		if( i <= LENBOUND ) printf("%d\n", i);
	}
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2011-08-30 09:35:51
Processing time 0.0889 sec