蓝桥杯打卡day03(3.6)

文章目录

      • 1.门牌制作
      • 2.[货物摆放](https://www.lanqiao.cn/problems/1463/learning/?page=1&first_category_id=1&sort=students_count)

1.门牌制作

package day03;

public class 门牌制作 {
   public static void main(String[] args) {
   	int res = 0;
   	for(int i = 1; i <= 2020; i ++)
   	{
   		res += count(i);
   	}	
   	System.out.println(res);
   }
   static int count(int num) {
   	int cnt = 0;
   	while(num != 0) {
   		if(num % 10 == 2)cnt++;
   		num /= 10;
   	}
   	return cnt;
   }
}

2.货物摆放

package day03;

import java.util.ArrayList;
import java.util.List;

public class 货物摆放 {
	public static void main(String[] args) {
		long m = 2021041820210418l;
		List<Long> arr = new ArrayList<>();
		for(long i = 1; i <= Math.sqrt(m); i ++) {
			if(m % i == 0) {
				arr.add(i);
				long value = m / i;
				if(value != i)arr.add(value);
			}
		}
		long res = 0;
		for(long a:arr) {
			for(long b:arr) {
				for(long c:arr) {
					if(a * b * c == m)res++;
				}
			}
		}
		System.out.println(res);
		
		
	}
}

你可能感兴趣的:(蓝桥杯,java,算法)