package margusmartseppcode.From_1_to_9;
public class Problem_1 {
// Arithmetic progression
static int AP(int nr) {
return nr * (nr + 1) / 2;
}
static int nAP(int nr, int multible) {
return multible * nr * (nr + 1) / 2;
}
public static void main(String[] args) {
int size = 999;
int result = nAP(size / 3, 3) + nAP(size / 5, 5)
- nAP(size / 15, 15);
System.out.println(result);
}
}
No comments:
Post a Comment