fork download
  1. import java.util.function.IntFunction;
  2.  
  3. class Ideone
  4. {
  5. public static void main (String[] args) throws java.lang.Exception
  6. {
  7. IntFunction f = (n) -> {for(int s=n,i=1;;i+=n)for(int j=2;i%j>0&j<i;)if(++j==i&&--s<1)return n>1?i:2;};
  8. int[] testlist = {1, 2, 3, 4, 5, 100, 123};
  9. for (int x : testlist) {
  10. System.out.println(f.apply(x));
  11. }
  12. }
  13. }
Success #stdin #stdout 0.3s 320704KB
stdin
Standard input is empty
stdout
2
5
19
29
71
39301
102337