Exemplo n.º 1
0
Arquivo: factor.c Projeto: d4g33z/lie
object Factor(bigint* num)
{ num=copybigint(num,NULL); 
  if (num->size<0) { Printf("- "); num->size=-num->size; }
  { bigint* temp=mkbigint(num->size); _digit p; int i=0;
    if (num->size==0) { Printf("0"); goto quit; }
    for (p=2; p<=trial_limit; p+= inc[i++])
    { if (i==array_size(inc)) i=3; /* after |37-31| wrap to difference |11-7| */
      
      if (copybigint(num,temp),div1(temp,p)==0)
      { _index n; _digit pn=p; int e=1;  copybigint(temp,num);
        for (n=1; pn<=MaxDigit/p; ++n) pn*=p; /* highest $p^n$ fitting in |_digit| */
        for (; div1(temp,pn)==0; e+=n) copybigint(temp,num);
          /* find factors $p^n$ */
        if (n>1) /* then there might be some factors |p| left */
          for (copybigint(num,temp); div1(temp,p)==0; ++e) copybigint(temp,num);
            /* factors |p| */
        Printf("%ld",(long)p);  if (e>1) Printf("^%ld",(long)e);
        if (cmp1(num,1)==0) goto quit; /* last factor was found */
        Printf(" * ");
      }
    }
    printbigint(num,0); 
    if (num->size>2) Printf(" (Last factor need not be a prime)");
  quit:  Printf("\n");
    freemem(num); freemem(temp);
  }
  return (object) NULL;
}
Exemplo n.º 2
0
Arquivo: sol.c Projeto: shhdup/msu-cs
int main(void) {
    A = readbigint();
    char tc; scanf("%c", &tc);
    B = readbigint();
    if (tc == '+') C = sum(A, B);
    if (tc == '-') C = diff(A, B);
    if (tc == '*') C = multiply(A, B);
    printbigint(C);
    return 0;
}