1028 Factoring Large Numbers

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

int isprime(long long num)
{
	int i;
	for(i = 2;  i <= sqrt((long double)num); i++)
	{
		if(num % i == 0) return 1;
	}
	return 0;
}

void getprime(long long num)
{
	long long i;
	for(i = 2; i <= num; i++)
	{

		if(isprime(i) == 0)
		{
			while(num % i == 0)
			{
				num = num / i;
				printf("%lld\n",i);
				if(isprime(num) == 0)
				{
					printf("%lld\n",num);
					return ;
				}
			}

		}
	}
}
int main()
{
	long long num;
	while(1)
	{
		scanf("%lld", &num);
		if(num  < 0) break;
		if(isprime(num) == 0)
			printf("%lld\n", num);
		else getprime(num);
		printf("\n");
	}
	return 0;
}

 

你可能感兴趣的:(number)