• Java Convention 公约数计算


    Java Convention 公约数计算

    /**
     * <html>
     * <body>
     *  <P> Copyright 1994-2018 JasonInternational </p>
     *  <p> All rights reserved.</p>
     *  <p> Created on 2018年4月10日 </p>
     *  <p> Created by Jason</p>
     *  </body>
     * </html>
     */
    package cn.ucaner.algorithm.sorts;
    
    /**
    * @Package:cn.ucaner.algorithm.sorts   
    * @ClassName:Convention   
    * @Description:   <p>Convention - 公约 </p>
    * @Author: - Jason   
    * @CreatTime:2018年4月23日 下午8:40:19   
    * @Modify By:   
    * @ModifyTime:  2018年4月23日
    * @Modify marker:   
    * @version    V1.0
     */
    public class Convention {
    	
    	/**
    	 * @Description: 求两数的最大公约数
    	 * @param m
    	 * @param n
    	 * @return int
    	 * @Autor: Jason - jasonandy@hotmail.com
    	 */
    	static int divisor(int m,int n){   
    		if(m%n==0){  
    			return n;  
    		}else{  
    			return divisor(n,m%n);  
    		}  
    	} 
    	
    	/**
    	 * @Description: 求两数的最小公倍数 
    	 * @param a
    	 * @param b
    	 * @return int
    	 * @Autor: Jason - jasonandy@hotmail.com
    	 */
    	static int gbs(int a,int b){  
    		int gbs = 0;  
    		gbs = a*b/divisor(a,b);  
    		return gbs;  
    	} 
    	
    	/**
    	 * @Description: Just for test 
    	 */
    	public static void main(String[] args) {
    		//int m = 1115;
    		//int n =828;
    		int m = 8;
    		int n = 12;
    		System.out.println(divisor(m,n));//最大公约数 
    		System.out.println(gbs(m, n));//最小公倍数
    	}
    	
    }
    

      

  • 相关阅读:
    桶排序
    基数排序
    计数排序
    归并排序
    快速排序
    优先级队列-堆实现
    堆排序
    红黑树
    【转】二叉树
    ubuntu 16.04 mysql 相关
  • 原文地址:https://www.cnblogs.com/jasonandy/p/9243202.html
Copyright © 2020-2023  润新知