1到n范围内能被5或6或8整除的数的个数
题目链接:https://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/2543.html
import java.util.Scanner;
import java.math.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while ( in.hasNext() ) {
int n = in.nextInt();
int ans = n/5 + n/6 + n/8 - n/30 - n/24 - n/40 + n/120 ;
System.out.println(ans);
//1到n被6整除数的个数为n/6(取整)。
//两两之间公倍数被算两次,减去一次;三个数公倍数被算三次,又被减三次,最后直接加一次
}
in.close();
}
}