Register
|
Login
Home
News
Competitions
Practice
How to
Rankings
Calendar
Arena
CodeFu 2007
CodeFu'07 Highlights
Jazoon'07 Highlights
Schedule
Rules
Prizes
Results
Competitions
»
Main CodeFu Competitons
»
CodeFu 2007
»
Results
CodeFu 2007 Results
CodeFu Final Round Results
Halicha's solution for 400: Square Count, written in Java
import java.util.ArrayList; import java.util.Iterator; public class SquareCount { public int pos(int N) { ArrayList<Integer> squares=new ArrayList<Integer>(); int i=2; int counter=1; int k=0; while(counter!=N){ double temp=Math.sqrt(i); //System.out.println(i+" "+Math.round(temp)+", "+temp); boolean isTheNum=true; if(Math.round(temp)==temp){ isTheNum=false; squares.add(i); } else{ int brojac=0; //Iterator<Integer>a=squares.iterator(); int granica=i/2; while(isTheNum&&(squares.size()>brojac)&&squares.get(brojac)<=granica){ if(i%squares.get(brojac)==0){ isTheNum=false; } brojac++; } if(isTheNum){ counter++; } if(counter==N) return i; } i++; } return 1; } /*public static void main(String[] args) { SquareCount a = new SquareCount(); System.out.print(a.pos(100)); /* int []niza=new int[1000000000]; for (int i = 2; i <1000000000 ; i++) {//Math.round(Math.sqrt(niza.length))+1 if(niza[i]==0){ for(int j=i*i;j<1000000000;j*=i) niza[j]=1; } } int rez=0; for (int i = 0; i < niza.length; i++) { if(niza[i]==1) rez++; System.out.println(niza[i]+" "+i); } System.out.print(rez); } */ }