int main() { /* The library throws `const char *' error messages when things go * wrong. It's a good idea to catch them using a `try' block like this * one. Your C++ compiler might need a command-line option to compile * code that uses exceptions. */ try { // Instead you can convert the number from a string. std::string s("1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678123456781234567812345678"); BigInteger a = stringToBigInteger(s); BigInteger b = stringToBigInteger(s); BigInteger c = a*b; // f is implicitly stringified and sent to std::cout. std::cout << "a\n" << a<<std::endl; std::cout << "b\n" << b<<std::endl; std::cout << "c\n" << c<<std::endl; // Let's do some heavy lifting and calculate powers of 314. int maxPower = 10; BigUnsigned x(1), big314(314); for (int power = 0; power <= maxPower; power++) { std::cout << "314^" << power << " = " << x << std::endl; x *= big314; // A BigInteger assignment operator } // Add your own code here to experiment with the library. } catch(char const* err) { std::cout << "The library threw an exception:\n" << err << std::endl; } std::string s; std::getline(std::cin, s); return 0; }
bool isLyrchel(int num){ BigInteger number = num; for(int i = 0; i < 50; i++){ std::string reversed = bigIntegerToString(number); std::reverse(reversed.begin(), reversed.end()); BigInteger rev = stringToBigInteger(reversed); number += rev; std::string temp = bigIntegerToString(number); if(isPalindrome(temp)) return false; } return true; }
void CBC_PDF417HighLevelEncoder::encodeNumeric(CFX_WideString msg, int32_t startpos, int32_t count, CFX_WideString& sb) { int32_t idx = 0; BigInteger num900 = 900; while (idx < count) { CFX_WideString tmp; int32_t len = 44 < count - idx ? 44 : count - idx; CFX_ByteString part = ((FX_WCHAR)'1' + msg.Mid(startpos + idx, len)).UTF8Encode(); BigInteger bigint = stringToBigInteger(part.c_str()); do { int32_t c = (bigint % num900).toInt(); tmp += (FX_WCHAR)(c); bigint = bigint / num900; } while (!bigint.isZero()); for (int32_t i = tmp.GetLength() - 1; i >= 0; i--) { sb += tmp.GetAt(i); } idx += len; } }
void ribi::QtToolSimplifyNewickMainDialog::OnAnyEditChange() noexcept { ui->button_start->setEnabled(false); ui->text_output->clear(); //Check newick try { const std::string s = ui->edit_newick->text().toStdString(); Newick::CheckNewick(s); ui->text_output->appendPlainText( QString("Current Newick: ") + QString(s.c_str())); } catch (std::exception& e) { ui->text_output->appendPlainText( QString("Invalid Newick: ") + QString(e.what())); return; } //Display current complexity { const NewickVector n( ui->edit_newick->text().toStdString()); const std::string s = ::bigIntegerToString(Newick::CalcComplexity(n.Peek())); ui->text_output->appendPlainText( QString("Current complexity: ") + QString(s.c_str())); } //Check complexity try { const std::string s = ui->edit_max_complexity->text().toStdString(); const BigInteger i = stringToBigInteger(s); if (i < 0) { ui->text_output->appendPlainText( "Invalid input of maximum complexity: " "must be bigger than zero"); return; } } catch (std::exception&) { //Too bad: BigInteger throws ordinary char pointers :-( ui->text_output->appendPlainText( "Invalid input of maximum complexity: " "must be a number"); return; } catch (...) { ui->text_output->appendPlainText( "Invalid input of maximum complexity: " "must be a number"); return; } //Set current maximum complexity to Newick complexity minus one { const NewickVector n( ui->edit_newick->text().toStdString()); const BigInteger newick_complexity = Newick::CalcComplexity(n.Peek()); const BigInteger current_complexity = ::stringToBigInteger(ui->edit_max_complexity->text().toStdString()); if (current_complexity > newick_complexity) { ui->edit_max_complexity->setText( QString(::bigIntegerToString(newick_complexity - 1).c_str())); } } ui->button_start->setEnabled(true); }