網頁

2011年9月22日 星期四

算gcd

計算gcd(123456789,999999999)

66 則留言:

  1. public class b9733054 {

    /**
    * @param args
    */
    static int gcd(int x,int y){

    int r=x%y;
    if(r==0)return y;
    else
    return gcd(y,r);
    }
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    int x=123456789;
    int y=999999999;
    System.out.println(gcd(x,y));

    }

    }

    回覆刪除
  2. class Program
    {

    static int gcd (int a, int b)
    {
    int r = a % b;
    if (r == 0) return b;
    else
    return gcd(b, r);
    }

    static void Main(string[] args)
    {
    int r;
    int x = 123456789,y=999999999;

    {
    Console.Write("GCD:");
    Console.WriteLine(gcd(x, y));
    Console.ReadLine();
    }
    }
    }
    }

    回覆刪除
  3. package pack1;
    public class a1 {
    public static void main(String[] args) {
    int x, y;
    System.out.print("最大公因函數為:");
    x = 123456789;
    y = 999999999;
    System.out.println(gcd(x, y));
    }
    static int gcd(int a, int b)
    {
    int c = a % b;
    if(c == 0)
    return b;
    else
    return gcd(b, c);
    }
    }

    回覆刪除
  4. import java.util.Scanner;
    public class V12313213 {
    public static void main(String args[]){
    int m,n,temp=0,tm,tn;

    Scanner choose=new Scanner(System.in);
    m=choose.nextInt();
    n=choose.nextInt();
    tm=m;
    tn=n;
    while(n!=0){
    temp=n;
    n=m%n;
    m=temp;

    }

    System.out.println("("+tm+","+tn+")="+m);

    }

    }

    回覆刪除
  5. import java.util.Scanner;
    public class V12313213 {
    public static void main(String args[]){
    int m,n,temp=0,tm,tn;

    Scanner choose=new Scanner(System.in);
    m=choose.nextInt();
    n=choose.nextInt();
    tm=m;
    tn=n;
    while(n!=0){
    temp=n;
    n=m%n;
    m=temp;

    }

    System.out.println("("+tm+","+tn+")="+m);

    }

    }

    回覆刪除
  6. import java.util.Scanner;
    public class V12313213 {
    public static void main(String args[]){
    int m,n,temp=0,tm,tn;

    Scanner choose=new Scanner(System.in);
    m=choose.nextInt();
    n=choose.nextInt();
    tm=m;
    tn=n;
    while(n!=0){
    temp=n;
    n=m%n;
    m=temp;

    }

    System.out.println("("+tm+","+tn+")="+m);

    }

    }

    回覆刪除
  7. public class B1 {
    static int gcd(int x,int y)
    {

    int r=x%y;
    if (r==0)return y;
    else return gcd(y,r);
    }

    public static void main(String[] args){

    System.out.println(gcd(123456789,999999999));
    }

    }

    回覆刪除
  8. package P1;
    public class B9933052A {

    static int gcd(int x , int y)
    {
    int r =x%y;
    if(r==0) return y;
    else
    return gcd(y,r);
    }
    public static void main(String[] args) {


    System.out.println(gcd(123456789 , 999999999));









    }

    }

    回覆刪除
  9. static int gcd (int x,int y)
    {
    int r = x % y;
    if (r == 0) return y;
    else
    return gcd (y, r);
    }

    static void Main(string[] args)
    {
    int x = 123456789, y = 999999999;
    {
    Console.Write("GCD:");
    Console.WriteLine(gcd(x, y));
    Console.ReadLine();

    }

    回覆刪除
  10. import java.util.Scanner;
    public class V12313213 {
    public static void main(String args[]){
    int m,n,temp=0,tm,tn;

    Scanner choose=new Scanner(System.in);
    m=choose.nextInt();
    n=choose.nextInt();
    tm=m;
    tn=n;
    while(n!=0){
    temp=n;
    n=m%n;
    m=temp;

    }

    System.out.println("("+tm+","+tn+")="+m);

    }

    }

    回覆刪除
  11. static int gcd(int a, int b)
    {
    int r = a % b;
    if (r == 0) return b;
    else
    return gcd(b, r);
    }
    static void Main(string[] args)
    {
    int x = 123456789,y=999999999;
    {

    Console.Write("GCD:");
    Console.WriteLine(gcd(x, y));
    Console.ReadLine();
    }

    回覆刪除
  12. using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace EX3
    {
    class Program
    {

    static int gcd(int x, int y)
    {
    int r = x % y;
    if (r == 0) return y;
    else
    return gcd(y, r);
    }

    static void Main(string[] args)
    {
    int x = 123456789, y = 999999999;
    {
    Console.Write("GCD:");
    Console.WriteLine(gcd(x, y));
    Console.ReadLine();

    }

    }
    }
    }

    回覆刪除
  13. import java.util.Scanner;
    public class V12313213 {
    public static void main(String args[]){
    int m,n,temp=0,tm,tn;

    Scanner choose=new Scanner(System.in);
    m=choose.nextInt();
    n=choose.nextInt();
    tm=m;
    tn=n;
    while(n!=0){
    temp=n;
    n=m%n;
    m=temp;

    }

    System.out.println("("+tm+","+tn+")="+m);

    }

    }

    回覆刪除
  14. class Program
    {

    static int gcd(int x, int y)
    {
    int r = x % y;
    if (r == 0) return y;
    else
    return gcd(y, r);
    }

    static void Main(string[] args)
    {
    int x = 123456789, y = 999999999;
    {
    Console.Write("GCD:");
    Console.WriteLine(gcd(x, y));
    Console.ReadLine();

    }

    }
    }
    }

    回覆刪除
  15. public class b99330114 {

    static int gcd(int x,int y)
    {

    int r=x%y;
    if(r==0)return y;
    else return gcd(y,r);
    }



    public static void main(String[] args) {
    System.out.println(gcd(123456789,999999999));

    }

    }

    回覆刪除
  16. import java.util.Scanner;
    public class V12313213 {
    public static void main(String args[]){
    int x,y,temp=0,tx,ty;

    x=123456789;
    y=999999999;
    tx=x;
    ty=y;
    while(y!=0){
    temp=y;
    y=x%y;
    x=temp;

    }

    System.out.println("("+tx+","+ty+")="+x);

    }

    }

    回覆刪除
  17. public class GCD
    {
    static int gcd(int x,int y)
    {
    int tmp;
    while (x % y != 0)
    {
    tmp = y;
    y = x % y;
    x = tmp;
    }
    return y;
    }

    public static void main(String[] args)
    {
    System.out.println(gcd(123456789,999999999));
    }
    }

    回覆刪除
  18. import java.util.Scanner;
    public class V12313213 {
    public static void main(String args[]){
    int m,n,temp=0,tm,tn;

    Scanner choose=new Scanner(System.in);
    m=choose.nextInt();
    n=choose.nextInt();
    tm=m;
    tn=n;
    while(n!=0){
    temp=n;
    n=m%n;
    m=temp;

    }

    System.out.println("("+tm+","+tn+")="+m);

    }

    }

    回覆刪除
  19. import java.util.Scanner;
    public class V12313213 {
    public static void main(String args[]){
    int x,y,temp=0,tx,ty;

    x=123456789;
    y=999999999;
    tx=x;
    ty=y;
    while(y!=0){
    temp=y;
    y=x%y;
    x=temp;

    }

    System.out.println("("+tx+","+ty+")="+x);

    }

    }

    回覆刪除
  20. package P1;
    public class B1 {

    static int gcd(int x,int y)
    {
    int r=x%y;
    if(r==0)return y;
    else return gcd(y,r);

    }

    public static void main(String[] args) {

    System.out.println(gcd(123456789,999999999));
    }

    }

    回覆刪除
  21. package test1;
    import java.util.Scanner;
    public class SS1 {

    public static void main(String[] args)
    {





    int m,n,temp=0,tm,tn;

    Scanner choose=new Scanner(System.in);
    m=choose.nextInt();
    n=choose.nextInt();
    tm=m;
    tn=n;
    while(n!=0){
    temp=n;
    n=m%n;
    m=temp;

    }

    System.out.println("("+tm+","+tn+")="+m);






















    }

    }

    回覆刪除
  22. using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace EX3
    {
    class Program
    {

    static int gcd(int x, int y)
    {
    int r = x % y;
    if (r == 0) return y;
    else
    return gcd(y, r);
    }

    static void Main(string[] args)
    {
    int x = 123456789, y = 999999999;
    {
    Console.Write("GCD:");
    Console.WriteLine(gcd(x, y));
    Console.ReadLine();

    }

    }
    }
    }

    回覆刪除
  23. import java.util.Scanner;
    public class V12313213 {
    public static void main(String args[]){
    int x,y,temp=0,tx,ty;

    x=123456789;
    y=999999999;
    tx=x;
    ty=y;
    while(y!=0){
    temp=y;
    y=x%y;
    x=temp;

    }

    System.out.println("("+tx+","+ty+")="+x);

    }

    }

    回覆刪除
  24. import java.util.Scanner;
    public class V12313213 {
    public static void main(String args[]){
    int x,y,temp=0,tx,ty;

    x=123456789;
    y=999999999;
    tx=x;
    ty=y;
    while(y!=0){
    temp=y;
    y=x%y;
    x=temp;

    }

    System.out.println("("+tx+","+ty+")="+x);

    }

    }

    回覆刪除
  25. import java.util.Scanner;
    public class V12313213 {
    public static void main(String args[]){
    int x,y,temp=0,tx,ty;

    x=123456789;
    y=999999999;
    tx=x;
    ty=y;
    while(y!=0){
    temp=y;
    y=x%y;
    x=temp;

    }

    System.out.println("("+tx+","+ty+")="+x);

    }

    }

    回覆刪除
  26. class gcd {
    public static int gcd(int m, int n) {

    if(n != 0)
    return gcd(n, m % n);
    else return m;

    }

    public static void main(String[] args) {
    System.out.println("GCD of (123456789,999999999) = " + gcd(123456789,999999999));
    }
    }

    回覆刪除
  27. package pack;

    public class pack {
    static int gcd(int x, int y)
    {
    int r = x%y;
    if (r==0)
    return y;
    else
    return gcd(y,r);
    }
    public static void main(String[] args) {

    System.out.println(gcd(123456789,999999999));



    }

    }

    回覆刪除
  28. import java.util.Scanner;
    public class V12313213 {
    public static void main(String args[]){
    int x,y,temp=0,tx,ty;

    x=123456789;
    y=999999999;
    tx=x;
    ty=y;
    while(y!=0){
    temp=y;
    y=x%y;
    x=temp;

    }

    System.out.println("("+tx+","+ty+")="+x);

    }

    }

    回覆刪除
  29. import java.util.Scanner;
    public class V12313213 {
    public static void main(String args[]){
    int x,y,temp=0,tx,ty;

    x=123456789;
    y=999999999;
    tx=x;
    ty=y;
    while(y!=0){
    temp=y;
    y=x%y;
    x=temp;

    }

    System.out.println("("+tx+","+ty+")="+x);

    }

    }

    回覆刪除
  30. import java.util.Scanner;
    public class V12313213 {
    public static void main(String args[]){
    int x,y,temp=0,tx,ty;

    x=123456789;
    y=999999999;
    tx=x;
    ty=y;
    while(y!=0){
    temp=y;
    y=x%y;
    x=temp;

    }

    System.out.println("("+tx+","+ty+")="+x);

    }

    }

    回覆刪除
  31. import java.util.Scanner;
    public class V12313213 {
    public static void main(String args[]){
    int x,y,temp=0,tx,ty;

    x=123456789;
    y=999999999;
    tx=x;
    ty=y;
    while(y!=0){
    temp=y;
    y=x%y;
    x=temp;

    }

    System.out.println("("+tx+","+ty+")="+x);

    }

    }

    回覆刪除
  32. import java.util.Scanner;
    public class V12313213 {
    public static void main(String args[]){
    int x,y,temp=0,tx,ty;

    x=123456789;
    y=999999999;
    tx=x;
    ty=y;
    while(y!=0){
    temp=y;
    y=x%y;
    x=temp;

    }

    System.out.println("("+tx+","+ty+")="+x);

    }

    }

    回覆刪除
  33. package PP1;

    public class GCD {

    static int gcd(int x,int y)
    {
    int tmp;
    while(x % y != 0)
    {
    tmp=y;
    y= x%y;
    x=tmp;
    }
    return y;
    }
    public static void main(String[] args) {

    System.out.println(gcd(123456789,999999999));
    }

    }

    回覆刪除
  34. package b1;
    public class b1 {

    public static void main(String[] args) {

    int m,n,gcd=0,tm,tn;
    m=123456789;
    n=999999999;
    tm=m;
    tn=n;
    while(n!=0){
    gcd=n;
    n=m%n;
    m=gcd;
    }
    System.out.println("("+tm+","+tn+")="+m);
    }
    }

    回覆刪除
  35. package p1;
    import java.io.*;
    public class A1 {

    static long gcd(long x ,long y)
    {
    if(y==0)return x;
    else
    return gcd(y,x%y);
    }
    public static void main(String[] args) throws Exception{
    long x=123456789;
    long y=888888888;
    long ans=gcd(x,y);
    System.out.println("最大公因數"+(ans));




    }

    回覆刪除
  36. static int gcd(int x, int y)
    {
    int r=x % y ;
    if(r==0) return y;
    else
    return gcd(y,r);

    }

    public static void main(String[] args) {
    int a, b;
    System.out.print("最大公因函數為:");
    a=123456789;
    b=999999999;
    System.out.println(gcd(a,b));
    }
    }

    回覆刪除
  37. package P1;

    public class A {

    static int gcd(int x,int y)
    {
    int r= x % y;

    if(r==0) return y ;

    else

    return gcd(y,r);

    }
    public static void main(String[] args) {
    int a , b;
    System.out.print("最大公因數:");
    a=123456789;
    b=999999999;
    System.out.println(gcd(a,b));
    }

    }

    回覆刪除
  38. package P1;
    import java.util.Scanner;
    public class A1
    {
    public static void main(String[] args)
    {
    int m,n,temp=0,tm,tn;

    Scanner choose=new Scanner(System.in);
    m=123456789;
    n=999999999;
    tm=m;
    tn=n;
    while(n!=0){
    temp=n;
    n=m%n;
    m=temp;

    }

    System.out.println("("+tm+","+tn+")="+m);



    }

    }

    回覆刪除
  39. import java.util.Scanner;

    public class b9933014 {
    public static void main(String[] args) {


    int x,y,temp=0,tx,ty;

    x=123456789;
    y=999999999;
    tx=x;
    ty=y;
    while(y!=0){
    temp=y;
    y=x%y;
    x=temp;

    }

    System.out.println("("+tx+","+ty+")="+x);





    }

    }

    回覆刪除
  40. package test1;
    import java.util.Scanner;
    public class SS1 {

    public static void main(String[] args)
    {





    int m,n,temp=0,tm,tn;

    Scanner choose=new Scanner(System.in);
    m=choose.nextInt();
    n=choose.nextInt();
    tm=m;
    tn=n;
    while(n!=0){
    temp=n;
    n=m%n;
    m=temp;

    }

    System.out.println("("+tm+","+tn+")="+m);























    }

    }

    回覆刪除
  41. package pack1;
    public class a1 {
    static int gcd(int a, int b)
    {
    int c = a % b;
    if(c == 0)
    return b;
    else
    return gcd(b, c);
    }
    public static void main(String[] args) {
    int x, y;
    System.out.print("最大公因函數為:");
    x = 123456789;
    y = 999999999;
    System.out.println(gcd(x, y));
    }
    }

    回覆刪除
  42. package p1;
    import java.io.*;
    public class C1 {
    static long gcd(long x,long y)
    {

    if(y==0)return x;
    else
    return gcd (y,x%y);
    }
    public static void main(String[] args)throws Exception {
    long x=123456789;
    long y=999999999;
    long ans=gcd(x,y);
    System.out.println("最大公因數="+(ans));

    回覆刪除
  43. package B1;

    public class b2
    {
    static int gcd(int x,int y)
    {
    int r=x%y;
    if(r==0)return y;
    else
    return gcd(y,r);
    }

    public static void main(String[] args)
    {
    int x=123456789;
    int y=999999999;
    System.out.println("gcd:"+ gcd(x,y));

    }

    }

    回覆刪除
  44. package p1;
    import java.io.*;
    public class C1 {
    static long gcd(long x,long y)
    {

    if(y==0)return x;
    else
    return gcd (y,x%y);
    }
    public static void main(String[] args)throws Exception {
    long x=123456789;
    long y=999999999;
    long ans=gcd(x,y);
    System.out.println("最大公因數="+(ans));

    回覆刪除
  45. package a1;

    public class a1 {

    static int gcd (int a , int b)
    {
    int c=a % b;
    if (c == 0)
    return b;
    else
    return gcd (b,c);
    }

    public static void main(String[] args) {
    int x,y;
    System.out.print("gcd=");
    x=123456789;
    y=999999999;

    System.out.print(gcd(x,y));
    }

    }

    回覆刪除
  46. import java.util.Scanner;

    public class A1 {

    public static void main(String[] args) {
    int x,y,temp=0,tx,ty;

    x=123456789;
    y=999999999;
    tx=x;
    ty=y;
    while(y!=0){
    temp=y;
    y=x%y;
    x=temp;
    }

    System.out.println("("+tx+","+ty+")="+x);
    }
    }

    回覆刪除
  47. import java.util.Scanner;
    public class V12313213 {
    public static void main(String args[]){
    int x,y,temp=0,tx,ty;

    x=123456789;
    y=999999999;
    tx=x;
    ty=y;
    while(y!=0){
    temp=y;
    y=x%y;
    x=temp;

    }

    System.out.println("("+tx+","+ty+")="+x);

    }

    }

    回覆刪除
  48. package P1;
    public class A1 {
    static int gcd(int x,int y)
    {
    int r=x % y;
    if(r==0)
    return y;
    else
    return gcd(y,r);
    }
    public static void main(String[] args)
    {
    int x=123456789;
    int y=999999999;
    System.out.println("最大公因數="+gcd(x,y));
    }
    }

    回覆刪除
  49. package P1;
    import java.util.Scanner;
    public class A1 {


    public static void main(String[] args) {


    int m,n,temp=0,tm,tn;

    Scanner choose=new Scanner(System.in);
    m=123456789;
    n=999999999;
    tm=m;
    tn=n;
    while(n!=0){
    temp=n;
    n=m%n;
    m=temp;

    }

    System.out.println("("+tm+","+tn+")="+m);

    }

    }

    回覆刪除
  50. package p1;
    import java.io.*;
    public class A1 {

    static long gcd(long x ,long y)
    {
    if(y==0)return x;
    else
    return gcd(y,x%y);
    }
    public static void main(String[] args) throws Exception{
    long x=123456789;
    long y=999999999;
    long ans=gcd(x,y);
    System.out.println("最大公因數"+(ans));




    }
    }

    回覆刪除
  51. package P1;
    import java.util.Scanner;
    public class A1
    {
    public static void main(String[] args)
    {
    int m,n,temp=0,tm,tn;

    Scanner choose=new Scanner(System.in);
    m=123456789;
    n=999999999;
    tm=m;
    tn=n;
    while(n!=0){
    temp=n;
    n=m%n;
    m=temp;

    }

    System.out.println("("+tm+","+tn+")="+m);



    }

    回覆刪除
  52. package pack1;
    public class A1 {
    public static void main(String[] args) {

    long a=123456789;
    long b=999999999;
    long ans=swap(a,b);
    System.out.println(ans);
    }
    static long swap (long a,long b)
    {
    if(b==0)
    return a;
    else
    return swap(b,a%b);

    }


    }

    回覆刪除
  53. package P1;
    import java.io.*;
    public class B9933019 {

    static long gcd (long x,long y)
    {
    if (y==0)
    return x;
    else return gcd (y,x%y);
    }
    public static void main (String[]args)
    {
    long x=123456789;
    long y=999999999;
    long s=gcd(x,y);
    System.out.println("最大公因數="+(s));
    }
    }

    回覆刪除
  54. public clss god
    pulic static void main(Stlng[]args){
    long a = 123456789
    long b = 999999999
    long ans=swop(a,b);
    System.outy.pringln(ans);
    }
    static long swap (long a , long b)
    {
    if (b ==0)
    return a;
    else
    return swop(b, a%b);
    }
    }

    swapo

    回覆刪除
  55. package B9933057;
    import java.io.*;
    public class B9933057 {

    static long gcd (long x,long y)
    {
    if (y==0)
    return x;
    else return gcd (y,x%y);
    }
    public static void main (String[]args)
    {
    long x=123456789;
    long y=999999999;
    long s=gcd(x,y);
    System.out.println("最大公因數="+(s));
    }
    }

    回覆刪除
  56. package A1;

    public class A1 {



    public static void main(String[] args) {
    long x=123456789;
    long y=999999999;
    long ans=swap(x,y);
    System.out.println(ans);


    }

    static long swap(long a,long b)
    {
    if(b==0)
    return a;
    else
    return swap(b,a%b);
    }

    }

    回覆刪除
  57. package pack;

    public class pack {
    static int gcd(int x, int y)
    {
    int r = x%y;
    if (r==0)
    return y;
    else
    return gcd(y,r);
    }
    public static void main(String[] args) {

    System.out.println(gcd(123456789,999999999));



    }

    }

    回覆刪除
  58. public class B1 {



    public static void main(String[] args) {
    long x=123456789;
    long y=999999999;
    long ans=swap(x,y);
    System.out.println(ans);

    }
    static long swap(long a,long b)
    {
    if(b==0)
    return a;
    else
    return swap(b,a%b);
    }
    }

    回覆刪除
  59. package pack1;
    public class A3 {
    public static void main(String[] args){
    long a=123456789;
    long b=999999999;
    long ans=smap(a,b);
    System.out.println(ans);
    }
    static long smap(long a,long b)
    {
    if(b==0)
    return a;
    else
    return smap(b,a%b);
    }


    }

    回覆刪除
  60. package pack1;
    import java.io.*;
    public class A1 {

    static long gcd(long x,long y)
    {
    if(y==0)
    return x;
    else
    return gcd (y,x%y);
    }
    public static void main(String[] args)
    {
    long x=123456789;
    long y=999999999;
    long s=gcd(x,y);
    System.out.println("最大公因數="+(s));



    }


    }

    回覆刪除
  61. package t1;
    import java.io.*;
    public class t1
    {
    static long gcd (long x,long y)
    {

    if (y==0)
    return x;
    else
    return gcd(y,x%y);
    }
    public static void main(String[] args)
    {
    long x=123456789;
    long y=999999999;
    long s=gcd(x,y);
    System.out.println("最大公因數="+(s));





    }

    }

    回覆刪除
  62. package pack1;
    public class A3 {
    public static void main(String[] args){
    long a=123456789;
    long b =999999999;
    long ans=smap(a,b);
    System.out.println(ans);
    }
    static long smap(long a,long b)
    {
    if(b==0)
    return a;
    else
    return smap(b,a% b);
    }

    }

    回覆刪除
  63. package pack1;
    public class A3 {
    public static void main(String[] args){
    long a=123456789;
    long b =999999999;
    long ans=smap(a,b);
    System.out.println(ans);
    }
    static long smap(long a,long b)
    {
    if(b==0)
    return a;
    else
    return smap(b,a% b);
    }

    }

    回覆刪除
  64. package pack;

    public class pack {
    static int gcd(int x, int y)
    {
    int r = x%y;
    if (r==0)
    return y;
    else
    return gcd(y,r);
    }
    public static void main(String[] args) {

    System.out.println(gcd(123456789,999999999));



    }

    }

    回覆刪除
  65. public class A1
    {
    public static void main(String[] args)
    {
    long a=123456789;
    long b=999999999;
    long ans=swap(a,b);
    System.out.println(ans);
    }

    static long swap(long a,long b)
    {
    if(b==0)
    return a;
    else
    return swap(b,a%b);
    }
    }

    回覆刪除
  66. public class B9933051
    {
    public static void main(String[] args)
    {
    long a=123456789;
    long b=999999999;
    long ans=swap(a,b);
    System.out.println(ans);
    }
    static long swap(long a,long b)
    {
    if(b==0)
    return a;
    else
    return swap(b,a%b);
    }
    }

    回覆刪除

HTML 編輯器