HJ55 挑7 | 题解
- 能整除, 则对7取余==0,
- 不能整除,则转化成字符串,看里面是否包含7
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { int n = in.nextInt(); int res = 0; for (int i = 1; i <= n; i++) { if (i % 7 == 0) res++; else if (String.valueOf(i).contains("7")) res++; } System.out.println(res); } } }