示例#1
0
void partitionPrimeHelper(int budget, int *partition, int pos)
{
  //BASE CASE!!!
  if (budget == 0){
    printpartition(partition, pos);
    return;
  }  

  //INDUCTIVE CASE!!!!!
  int spending;
  for(spending = 2; spending <= budget ; spending++){
    if(!Isprime(spending)) continue;
    partition[pos] = spending;
    partitionPrimeHelper(budget - spending, partition, pos + 1);
  }
}
示例#2
0
文件: Factor.cpp 项目: lancerd/OJCODE
void comfactor(const LL &n, vector<LL> &v)
{
    if(n<1e9) {
        smallfactor(n,v);
        return;
    }
    if(Isprime(n)) {
        v.push_back(n);
        return;
    }
    LL d;
    for(int c=3;;++c) {
        d = pollorrho(n,c);
        if(d!=n) break;
    }
    comfactor(d,v);
    comfactor(n/d,v);
}
int main(void)
{
	largeInt l1, l2,l3,sum,diff,product;
	largeNum n1, n2,sumn;
	div_result divi;
	int x,prime_n1,prime_n2;
	printf("Enter 1st number:");
	readint(&l1);
	
	printf("\n");
	printf("Enter 2nd number:");
	readint(&l2);
	printf("\nThe 1st number is :\n");
	showI(l1);
	printf("\nThe 2nd number is :\n");
	showI(l2);
	printf("\n");
	
//	printf("chk_equal=%d",chk_equal(l1,l2));
//	printf("\n");

	
//	showI(increment1(l1));
	
//	fwriteI(l3);

//	printf("\nequal zero: %d",equal_to_zero(n1));

//	shift(&n1,3);
//	showN(n1);
//	shift(&n1,-2);
//	showN(n1); 

//	printf("\nAfter removing all zeroes from left;"); 	
//	rem_all_zeros_from_left(&n1);
//	showN(n1);	
	
//	x=equal_to_zero(l1);
//	printf("\n Value of x: %d\n",x);

//	x=greaterthan(l1,l2);
//	printf("\n Value of x: %d\n",x);
	
	sum=addl(l1,l2); // Addition..
	printf("\n\nSum=");
	showI(sum);
	
//	sumn=add_n_times(n1,2);
//	printf("\nSUM_N=");
//	showN(sumn);
	
	diff=subl(l1,l2);
	printf("\n\nDifference=");
	showI(diff);
	
	product=multl(l1,l2);
	printf("\n\nproduct=");
	showI(product);
	
	printf("\n\n");

//	append_n_zeros_right(&n1,2);
//	showN(n1);
//	remove_one_zero_right(&n1);
//	printf("\n");
//	showN(n1);

	divi=divl(l1,l2);
	showDiv(divi);
	
	printf("\nmodulus of 1st and 2nd number:");
	showI(modl(l1,l2));
	
	x=Isprime(l1);
	if(x==1)
		printf("\nPRIME");
	else
		printf("\nNOT PRIME\n");
	
	return 0;
}