Original title link: http://lx.lanqiao.cn/problem.page?gpid=T332
Welcome to my Blue Bridge Cup OJ Problem Solution~ https://blog.csdn.net/richenyunqi/article/details/80192062
Algorithms improve simple addition
Time limit: 1.0s Memory limit: 256.0MB
Problem Description
Four of the natural numbers less than 10 are divisible by 3 or 5 (3, 5, 6, 9), and their sum is 23.
Please calculate the sum of all natural numbers less than 1000 that are divisible by 3 or 5. Then use standard output to cout to output your results.
Please calculate the sum of all natural numbers less than 1000 that are divisible by 3 or 5. Then use standard output to cout to output your results.
input format
without.
output format
One integer per line, representing your result.
public class Main { public static void main(String[] args) { int k=0; for(int i=3;i<1000;++i){ if(i%3==0||i%5==0){ k+=i; } } System.out.println(k); } }