Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

萌新贴码

Posted by XianYugong at 2017-03-24 09:24:59 on Problem 3006
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int a, d, n;
int main()
{
	int prime(int x);
	while(scanf("%d %d %d",&a,&d,&n)!=EOF)
	{
		if (a > 0 && a <= 9307 && d > 0 && d <= 346 && n > 0 && n <= 210)
		{
			int sum = 0, count = 0;
			for (int i = 0; ; i++)
			{
				sum = a + i*d;
				if (sum == 2 || sum == 3)
					count++;
				else if (sum == 1) continue;
				else 
					if(prime(sum))
					count++;
				if (count == n)
					break;
			}
			printf("%d\n", sum);
		}
		else
			exit(0);
	}
	if (prime(83)) printf("是素数");
	else printf("不是素数");

	return 0;
}
int prime(int x)
{
	int i=2;
	for (; i <= sqrt(x); i++)
	{
		if (x%i == 0)
			return 0;
	}
	return 1;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator