Skip to content

Instantly share code, notes, and snippets.

@gaoyike
Created September 29, 2014 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaoyike/4f12a0a7731c09c6da96 to your computer and use it in GitHub Desktop.
Save gaoyike/4f12a0a7731c09c6da96 to your computer and use it in GitHub Desktop.
package Basic;
import java.util.Arrays;
/**
* Created by chenguanghe on 9/29/14.
*/
public class DistictProducts {
public static int products(int n) {
boolean[] test = new boolean[n*n+1];
Arrays.fill(test, false);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
test[i*j] = true;
}
}
int count = 0;
for (boolean b : test){
if(b)
count++;
}
return count;
}
public static void main(String[] args) {
for (int i = 1; i <=10 ; i++) {
System.out.print(products(i)+", ");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment