Exemple #1
0
int main()
{
	int nprob, curprob, idx, order, count;

	if(fgets(&(inbuf[0]), 255, stdin) == NULL)
	{
		fprintf(stderr, "Read failed on problem count\n");
		return -1;
	}
	if(sscanf(&(inbuf[0]), "%d", &nprob) != 1)
	{
		fprintf(stderr, "Scan failed on problem count\n");
		return -2;
	}
	MakePrimes();
	for(curprob = 1; curprob <= nprob ; curprob++)
	{
		if(fgets(&(inbuf[0]), 255, stdin) == NULL)
		{
			fprintf(stderr, "Read failed on problem %d header\n", curprob);
			return -3;
		}
		// get prob num and order of sequence
		if(sscanf(&(inbuf[0]), "%d %d", &idx, &order) != 2)
		{
			fprintf(stderr, "scan failed on problem header problem idx %d\n",
				curprob);
			return -6;
		}
		if(idx != curprob)
		{
			fprintf(stderr, "problem idx %d not = expected problem %d\n",
				idx, curprob);
			return -7;
		}
		if((order < 1) || (order > MAX_ORDER)) {
			fprintf(stderr, "problem idx %d order %d not in range 1-%d\n",
				curprob, order, MAX_ORDER);
			return -8;
		}
		count = farey(order);
		printf("%d %d\n", idx, count);
	}
	return 0;
}
Exemple #2
0
int main(void){
	while(scanf("%u %u",&n,&show)!=EOF) farey();
	return 0;
}