请从小到大打印出3、5的前10个公倍数,比如15、30、45等(注意公倍数是整数),求求了

请从小到大打印出3、5的前10个公倍数,比如15、30、45等(注意公倍数是整数),求求了
List<int> threeList = new List<int>();
List<int> fiveList = new List<int>();
int threeIndex = 1;
int fiveIndex = 1;
while(threeList.length < 10) {
    if(threeIndex % 3 == 0) {
        threeList.add(threeIndex );
    }
    threeIndex ++
}
while(fiveList.length < 10) {
    if(fiveIndex % 5 == 0) {
        threeList.add(fiveIndex );
    }
    fiveIndex ++
}

 

Java

10个就是最小公倍数 *1,*2,*3.....*10,10个

就判断把,两个不相等正数公倍数,如果MAX能被MIN整除,那么最小公倍数就是MAX,如果不能,则最小公倍数就是MAX*MIN

比如2,和4的公倍数,就是 4*1,4*2,4*3.....4*10,,3和5的公倍数就是 3*5*1,3*5*2,3*5*3....3*5*10,这样,相比单纯的循环要少很多运算次数,你可以这样自己实现下