Beispiel #1
0
int main(int argc, char*argv[])
{
	TimeStats ts;
	auto primes = primeList(np);
	auto facs = primeFactor(num,primes);
	ts.toc();
	std::cout<<ts.milliseconds()<<" ms"<<std::endl;
}
std::vector<int> evenRepartition(plint value, plint d) {
    std::vector<int> primeFactors = primeFactor(value);
    std::vector<int> repartition(d);
    for (plint iRep=0; iRep<d; ++iRep) {
        repartition[iRep] = 1;
    }
    plint iDim=0;
    for (plint iPrime=(int)(primeFactors.size()-1); iPrime>=0; --iPrime) {
        repartition[iDim] *= primeFactors[iPrime];
        iDim = (iDim+1)%d;
    }
    return repartition;
}
Ind findNextPrime(std::list<Ind>& primes, Ind maxPrime)
{
	Ind i = primes.back()+1;
	while(true)
	{
		if (primeFactor(primes, i)==i)
		{
			primes.emplace_back(i);
			return i;
		}
		++i;
	}
}
Beispiel #4
0
void primeFactor(uint64_t n)
{
	uint64_t i,limit = sqrt(n);
	for(i=2 ; i<=limit ; i++)
	{
		if(n%i == 0)
		{
            printf(" %ju",i);
			primeFactor(n/i);
			return;
		}
	}
    printf(" %ju",n);
}
main()
{
	int selection = 0;
	int c=0;
	
	do //begin do while
	{
		float x=0;
		float y=0;
		float fResult=0;
		int ix=0;
		int iy=0;
		int iResult=0;
		int factor=0;
		int temp=0;
		int*pResult=0;
	printf("\nCalculator Menu\n\n");
	printf("[1]\tAddition\n");
	printf("[2]\tSubtraction\n");
	printf("[3]\tMultiplication\n");
	printf("[4]\tDivision\n");
	printf("[5]\tModulus (Integers Only)\n");
	printf("[6]\tPrime Test (Integers Only)\n");
	printf("[7]\tFactorial (Integers Only)\n");
	printf("[8]\tPower\n");
	printf("[9]\tFibonacci Sequence\n");
	printf("[0]\tExit\n");
		
	printf("\nPlease Select an option: ");
	scanf("%d",&selection);
	
	switch(selection)
	{
		case 1://Addition
			{
				printf("\nYou have selected \"Addition\"");
				printf("\nx + y = ?");
				printf("\nPlease input a value for \"x\": ");
				scanf("%f",&x);
				printf("\nPlease input a value for \"y\": ");
				scanf("%f",&y);
				addTwoNumbers(x,y);
				printf("\n-------------------------------------------");
				break;
			}
		case 2://Subtraction
			{
				printf("\nYou have selected \"Subtraction\"");
				printf("\nx - y = ?");
				printf("\nPlease input a value for \"x\": ");
				scanf("%f",&x);
				printf("\nPlease input a value for \"y\": ");
				scanf("%f",&y);
				subTwoNumbers(x,y);
				printf("\n-------------------------------------------");
				break;
			}
		case 3://Multiplication
			{
				printf("\nYou have selected \"Multiplication\"");
				printf("\nx * y = ?");
				printf("\nPlease input a value for \"x\": ");
				scanf("%f",&x);
				printf("\nPlease input a value for \"y\": ");
				scanf("%f",&y);
				multTwoNumbers(x,y);
				printf("\n-------------------------------------------");
				break;
			}
		case 4://Division
			{
				printf("\nYou have selected \"Division\"");
				printf("\nx // y = ?");
				printf("\nPlease input a value for \"x\": ");
				scanf("%f",&x);
				printf("\nPlease input a value for \"y\": ");
				scanf("%f",&y);
				divTwoNumbers(x,y);
				printf("\n-------------------------------------------");
				break;
			}
		case 5://Modulus
			{
				printf("\nYou have selected \"Modulus\"");
				printf("\nx %% y = ?");
				printf("\nPlease input an integer value for \"x\": ");
				scanf("%d",&ix);
				printf("\nPlease input an integer value for \"y\": ");
				scanf("%d",&iy);
				modTwoNumbers(ix,iy);
				printf("\n-------------------------------------------");
				break;
			}
		case 6://Prime Test
			{
				printf("\nYou have selected \"Prime Test\"");
				printf("\nTest if x is prime");
				printf("\nPlease input an integer value for \"x\": ");
				scanf("%d",&ix);
				primeFactor(ix);
				printf("\n-------------------------------------------");
				break;
			}
			case 7://Factorial
			{
				printf("\nYou have selected \"Factorial\"");
				printf("\nx!");
				printf("\nPlease input an integer value for \"x\": ");
				scanf("%d",&ix);	
				factorial(ix);
				printf("\n-------------------------------------------");
				break;	
					
			}
			case 8://Power
			{
				printf("\nYou have selected \"Power\"");
				printf("\nx to the power of y");
				printf("\nPlease input a value for \"x\": ");
				scanf("%f",&x);
				printf("%f",x);
				printf("\nPlease input an integer value for \"y\": ");
				scanf("%d",&ix);
				powerOf(x,ix);
				printf("\n-------------------------------------------");
				break;
			}
			case 9://Fibonacci
			{
				printf("\nYou have selected \"Fibonacci Sequence\"");
				printf("\nDisplay the Fibonacci Sequence up to and including n=x");
				printf("\nPlease input an integer value for \"x\": ");
				scanf("%d",&ix);	
				fibonacci(ix);
				printf("\n-------------------------------------------");
				break;				
			}
			case 0://Exit
			{
				printf("\nHave a nice day!");
				printf("\n-------------------------------------------");
				break;
			}
			default://Invalid
			{
				printf("\nInvalid Option!\nPlease sekect a valid option!");
				printf("\n-------------------------------------------");
				break;
			}
	}
	
	
	
	}while(selection!=0);
	
	return 0;
}
Beispiel #6
0
void print_prime_factors(uint64_t n)
{
    printf("%ju :",n);
	primeFactor(n);
    printf("\n");
}