Wednesday, June 11, 2014

how many ?

a Discreet math problem...

How many integers are NOT divisble by 3,7 or 9 ?

import java.math.*;
import static sun.util.calendar.CalendarUtils.mod;
       
public class Divisible {
    public static void main(String[] args) {
        int count = 0;
        for (int i = 2; i < 1000; i++){
            if (
                mod(i,3)== 0 ||
                mod(i,7)== 0 ||
                mod(i,9)== 0){
            count++;
            }           
        }
      // print the tally - 998 - all those divisible by 3,7 or 9
        count = (1000-2)-count;
    System.out.println(count);
    }
}
Post a Comment

Follow by Email