出题者楼层及时间:第74#,时间为:2013年3月30日
答题者次数:我是本题的第2位答题者,上一个答题者楼层数为:90楼。- public static void main(String[] args)
- {
- Scanner cin = new Scanner(System.in);
- while(cin.hasNext())
- {
- int n = cin.nextInt();
- int m = cin.nextInt();
- int t = GCD(n,m);
- System.out.println("最大公约数"+t);
- System.out.println("最小公倍数"+(n*m/t));
- }
- }
- public static int GCD(int a, int b)
- {
- int t;
- while((t=a%b)!=0)
- {
- a=b;b=t;
- }
- return b;
- }
复制代码 结题思路和90#大同小异....都是GCD的问题。我本来想用快速GCD来做的。后来想想算了吧!还是辗转相除吧
不知能给分否??现在用vector容器写一个题目 |