Java program that prints out numbers that are divisible by other numbers

前端 未结 2 1326
余生分开走
余生分开走 2021-01-28 01:25

I have a program that reads two real numbers and then it prints out all the numbers between these two, that are divisible by 2 or 3 or 5. The program works fine, but when a use

2条回答
  •  孤城傲影
    2021-01-28 01:35

    Not really an answer, but with my low reputation score I am not permitted to post a comment.

    If a number is divisible by 2, or 3, or 5 does not change if you add or subtract 30 (= 2* 3* 5) from that number. So you can count the matching numbers from 1 to 30, then compute how many blocks of 30 numbers are in your range, and then count the matching numbers that are not covered by those blocks.

提交回复
热议问题