Hduoj1164 【数学】【素数】

/*Eddy's research I
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6626    Accepted Submission(s): 3964


Problem Description
Eddy's interest is very extensive, recently he is interested in prime number. Eddy discover the all number owned can be
 divided into the multiply of prime number, but he can't write program, so Eddy has to ask intelligent you to help him,
  he asks you to write a program which can do the number to divided into the multiply of prime number factor .


Input
The input will contain a number 1 < x<= 65535 per line representing the number of elements of the set.


Output
You have to print a line in the output for each entry with the answer to the previous question.

 

Sample Input
11
9412
 

Sample Output
11
2*2*13*181
 

Author
eddy
*/ 
#include<stdio.h>
int prime[35000], a[35000], len;
void isprime()
{
	a[0] = 1;
	a[1] = 1;
	int i, k, j;
	for(i = 2; i < 35000; i++)
	{
		for(j = 2*i; j < 35000; j += i)
		a[j] = 1; 
	}
	len = 0;
	for(i = 2; i < 35000; i++)//素数表
	if( !a[i])
	prime[len++] = i; 
}
int main()
{
	int i, j, k, m, n;
	isprime();
	while(scanf("%d", &n) != EOF)
	{
		k = 0;
		while(prime[k] <= n)//打印素数
		{
			if(n % prime[k] == 0)
			{
				if(prime[k] == n)
					printf("%d\n", n);
				else
					printf("%d*",prime[k]);
				n /= prime[k];
			}
			else
			k++;
		}
	}
	return 0;
}

你可能感兴趣的:(c)