Exemplo n.º 1
0
int32 problem104() {
  BigInteger f1(1);
  BigInteger f2(1);
  int32 k = 2;
  string front = "123456789";
  string back = "123456789";
  while (true) {
    k++;
    BigInteger temp = f1 + f2;
    f1 = f2;
    f2 = temp;
    if (temp.numberOfDigits() < 18) {
      continue;
    }

    for (int32 i = 0; i < 9; i++) {
      back[i] = temp.getNthDigitFromRight(i) + '0';
    }
    if (isPandigital(back)) {
      for (int32 i = 0; i < 9; i++) {
        front[i] = temp.getNthDigitFromLeft(i) + '0';
      }
      if (isPandigital(front)) {
        return k;
      }
    }
  }
}
Exemplo n.º 2
0
BigInteger multiply(BigInteger &x, int y, int pos = 0) {
    int nx = x.numberOfDigits();
    BigInteger z;
    int carry = 0;
    for (int i = 0; i < nx; i++) {
        carry += x.getDigit(i) * y;
        z.setDigit(pos++, carry % 10);
        carry /= 10;
    }
    while (carry > 0) {
        z.setDigit(pos++, carry % 10);
        carry /= 10;
    }
    return z;
}