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