Skip to main content

First post using stackedit

Welcome to StackEdit! Hey! I’m your first Markdown document in StackEdit 1 . Don’t delete me, I’m very helpful! I can be recovered anyway in the Utils tab of the Settings dialog. Documents StackEdit stores your documents in your browser, which means all your documents are automatically saved locally and are accessible offline! Note: StackEdit is accessible offline after the application has been loaded for the first time. Your local documents are not shared between different browsers or computers. Clearing your browser’s data may delete all your local documents! Make sure your documents are synchronized with Google Drive or Dropbox (check out the Synchronization section). Create a document The document panel is accessible using the button in the navigation bar. You can create a new document by clicking New document in the document panel. Switch to another document All your local documents are listed in the document panel. You can switch from one to anoth...

Project Euler: problem 3

Đề bài:

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

Tức là tìm ước số nguyên tố lớn nhất của 600851475413.

Bài này thì đương nhiên là quá dễ, tuy nhiên nếu viết bằng C++ thì cần chú ý là không thể sử dụng các kiểu cơ bản như long, vì sẽ bị tràn số.

Sử dụng kiểu long long int, và chú ý là thêm LL vào sau giá trị của biến có kiểu long long int.

Mã nguồn được viết và biên dịch bởi Code:Blocks 8.02, Windows XP.


#include

#include


bool check_prime (long long int a) {

    if (a==2) return true;

    for (long long int i = 2; i <= sqrt(a); i++) {

        if (a % i == 0) return false;

    }

    return true;

}


int main() {

    long long int n = 600851475143LL;

    long long int s = long(sqrt(n));

    for (long long int i = s; i >= 2; i--) {

        if ((n % i == 0) && check_prime(i)) {

            cout <<>

            break;

        }

    }

}

Comments

Popular posts from this blog

First post using stackedit

Welcome to StackEdit! Hey! I’m your first Markdown document in StackEdit 1 . Don’t delete me, I’m very helpful! I can be recovered anyway in the Utils tab of the Settings dialog. Documents StackEdit stores your documents in your browser, which means all your documents are automatically saved locally and are accessible offline! Note: StackEdit is accessible offline after the application has been loaded for the first time. Your local documents are not shared between different browsers or computers. Clearing your browser’s data may delete all your local documents! Make sure your documents are synchronized with Google Drive or Dropbox (check out the Synchronization section). Create a document The document panel is accessible using the button in the navigation bar. You can create a new document by clicking New document in the document panel. Switch to another document All your local documents are listed in the document panel. You can switch from one to anoth...

Getting started with Cryptpad in Ubuntu: step by step

Cryptpad is an open source collaborative editor which is hosted at: https://github.com/cjdelisle/cryptpad It is easy to clone the github repository and start to try, but if you are a newbie, there maybe some difficulties. Suppose that you have a clean Ubuntu machine, and want to try with Cryptpad, you can follow these steps: 1. Download mongodb for Linux: https://www.mongodb.org/downloads 2. Unzip the file you got to a location you want. You will start mongodb from there, or add this directory to your PATH variable so you can start mongodb from anywhere. 3. Suppose that you chose the easier way, i.e start mongodb from its directory. 4. Open Terminal (Ctrl + Alt + T for shortcut), move to the directory of mongodb 5. Type: mkdir db mongod --dbpath=./db These above commands will first, create a directory 'db' insider the directory mongodb, then start mongodb server. 6. Keep the terminal with mongodb server running 7. Open another terminal (Ctrl...

Install latest R (3.2.5) on Debian Jessie

Installing R on Ubuntu/Debian is quite painful, especially when you want to install the latest version. I have no clue why this situation stills for a long time, but this is a way to work around. On terminal: ```bash Appends the CRAN repository to your sources.list file You could replace jessie-cran3 by the newer one Find the correct value at https://cloud.r-project.org/ sudo sh -c 'echo "deb http://cran.rstudio.com/bin/linux/debian jessie-cran3/" >> /etc/apt/sources.list' Adds the CRAN GPG key, which is used to sign the R packages for security. sudo apt-key adv --keyserver subkeys.pgp.net --recv-key 381BA480 sudo apt-get update sudo apt-get install r-base r-base-dev ``` Installing h2o : ```bash to retrieve curl-config otherwise you may have a problem with RCurl sudo apt-get install libcurl4-gnutls-dev ``` R install.packages ("h2o")