PAT_B_1013 number prime

Subject description:

So that P i denotes the i th prime number. The current to both positive integers M≤N≤10 ^ 4, to make all the output P M P N of a prime number. 
Input format: 
input given M and N in a row, separated by a space therebetween. 
Output format: 
output from all primes P M P N, each representing a digit line 10, separated by spaces therebetween, the end of the line may not have extra space. 
Sample input: 
527 
Output Sample: 
1,113,171,923,293,137 43 is 41 is 
4,753,596,167,717,379 83 89 
97 101 103

I AC Code:

//  输出第 M 到 第 N 个 素数

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

int Is_Prime(int);

int main(void)
{
	int i;
	int N1, N2;
	int n = 105000; 
	int flag = 0;
	int flag_ch = 0;
	
	scanf("%d %d",&N1,&N2);
	
	for (i=1; i<n; i++)	
	{
		if (Is_Prime(i))
		{
			flag++;
			if (flag>N1 && flag<=N2+1)
			{
				flag_ch++;
				printf("%d",i);
				if (flag_ch<10 && flag!=N2+1)
				{
					printf(" ");
				}
				else
				{
					printf("\n");
					flag_ch -= 10;
				}
			}
					
		}
			
	}
	return 0;
}

int Is_Prime(int n)
{
	int i = 1;
	int temp = sqrt(n);
	
	for (i=2; i<=temp; i++)	
	{
		if (n%i == 0)
			return 0;
	}
	return 1;
}

RRR

Guess you like

Origin www.cnblogs.com/Robin5/p/11243621.html