2028,2085

题目:Lowest Common Multiple Plus

Lowest Common Multiple Plus

思路:一开始选择是去寻找各个倍数的规律,但发现其算起来较为复杂,且自己的想法也无法得到最后结果。最后采用了枚举法来做这题,每次只进行两数相比较,取其中最大值,每次加1,直到该值对于两个数都取余为0。

import java.util.*;
public class Main {
public static void main(String[] args) {
    Scanner scan = new Scanner(System.in) ;
    while(scan.hasNextInt()) {
        int n =scan.nextInt();
        int num,flag=1;
        while(n-->0) {
            num = scan.nextInt();
            int k=Math.max(num, flag);
            int t=k;
            int i=Math.min(num, flag);
            for(;;k++) {
                if(k%i==0) {
                    if(k%t==0) {
                        break;
                    }
                }
            }
            flag = k;
        }
        System.out.println(flag);
    }
}
}

题目:核反应堆

核反应堆

思路:其计算是将高能质点与低能质点分开计算(其中可用循环来一次次计算),每多一次高能为前一次高能质点数目的3倍与低能质点数目2倍之和,而低能质点为前一次高能质点与低能质点数目之和。

import java.util.*;
public class Main {
public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    while(scan.hasNextInt()) {
        int n = scan.nextInt();
        long  i,j,da=1,xiao=0;
        if(n==-1) break;
        else {
            for(i=0;i<n;i++) {
                j=da;
                da = da*3+xiao*2;
                xiao = xiao+j;
            }
        }
        System.out.println(da+", "+xiao);
    }
}
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。