You are viewing a single comment's thread. Return to all comments →
public static String sillyGame(int n) { // Write your code here if(n==1 || n==3 || n==4 || n==7 || n==8 || n==9 || n==10 ){ return "Bob"; } if(n==2 || n==5 || n==6 ){ return "Alice"; } List<Integer> list=new ArrayList<>(); List<Integer> li=new ArrayList<>(); li.add(2); li.add(3); li.add(5); li.add(7); for(int i=11;i<=n;i++){ if(i%2==0 || i%3==0 || i%4==0 || i%5==0 || i%6==0 || i%7==0 || i%8==0 || i%9==0 || i%10==0){ continue; }else{ list.add(i); } } int c; for(int i=0;i<list.size();i++){ c=0; for(int j=4;j<li.size();j++){ if(li.get(j)>(int)Math.sqrt(list.get(i))){ break; } if(list.get(i)%li.get(j)==0){ c++; break; }else{ continue; } } if(c==0){ li.add(list.get(i)); } } System.out.println(list.size()); System.out.println(li.size()); if(li.size()%2==0){ return "Bob"; } else{ return "Alice"; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Alice and Bob's Silly Game
You are viewing a single comment's thread. Return to all comments →
Java