xcorp::When it rains, it pours.

"The nice thing about rain," said Eeyore, "is that it always stops. Eventually."

最後の問題

C で組んでみましたが,枝狩りありで 3.36sec,枝狩りなしで 5sec くらいでした。

で、その超手抜きソースが↓これ。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>

#define TRUE 1
#define FALSE 0

int main(void)
{
	int a, b, lim_a, lim_b, idx_a, idx_b, mul, is_found, cnt;
	long sec, usec;
	unsigned long long int total;
	char buf[64];
	struct timeval t1, t2;

	a = 0;
	cnt = 0;
	total = 0;
	lim_a = 1000;
	lim_b = 10000;
	gettimeofday(&t1, NULL);

	while (a < lim_a) {
		if ((a % 10) != 0) {
			b = 0;
			while (b < lim_b) {
				if (((b % 10) == 0) && (((a % 2) == 0) && ((b % 5) == 0)) && (((a % 5) == 0) && ((b % 2) == 0))) {
					b++;
					continue;
				}
				mul = a * b;
				sprintf(buf, "%d", mul);
				idx_a = 0;
				idx_b = strlen(buf) - 1;
				while (TRUE) {
					if (idx_a >= idx_b) {
						is_found = TRUE;
						break;
					}
					if (buf[idx_a] != buf[idx_b]) {
						is_found = FALSE;
						break;
					}
					idx_a++;
					idx_b--;
				}
				if (is_found != FALSE) {
					cnt++;
					total += mul;
					printf("FOUND: %d * %d = %d\n", a, b, mul);
				}
				b++;
			}
		}
		a++;
	}
	gettimeofday(&t2, NULL);
	if (t2.tv_usec < t1.tv_usec) {
		sec = t2.tv_sec - (t1.tv_sec + 1);
		usec = t1.tv_usec - t2.tv_usec;
	}
	else {
		sec = t2.tv_sec - t1.tv_sec;
		usec = t2.tv_usec - t1.tv_usec;
	}
	printf("elapsed time: %ld.%06ld\n", sec, usec);
	printf("found: %d, total: %llu\n", cnt, total);
	return 0;
}

何をするプログラムなのかとかヤボなコトを聞いちゃいけませんよ(笑