1011 Greatest common divisor gcd

Source: Internet
Author: User
Tags greatest common divisor

1011 Greatest common divisor GCD

Base time limit:1 seconds space limit:131072 KB

Enter 2 positive integers a,b, ask a and b the greatest common divisor.

Input

2 number A, B, separated by a space in the middle. (1<=, b <= 10^9)

Output

Outputs A and B of the greatest common divisor.

Input Example

30 105

Output Example

15

ImportJava.util.Scanner; Public classMain {Static intgcdintAintb) {        returnA%b==0? B:GCD (b,a%b); }     Public Static voidMain (string[] args) {//TODO auto-generated Method StubScanner sc=NewScanner (system.in);  while(Sc.hasnext ()) {intA=Sc.nextint (); intb=Sc.nextint ();        System.out.println (GCD (A, b));    } sc.close (); }}

1011 Greatest common divisor gcd

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.