fork download
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. class Main {
  5. /*LEAFEAT*/
  6.  
  7. public static void main(String[] args) {
  8. Scanner reader = new Scanner(System.in);
  9. String firstLine = reader.nextLine();
  10. //N is the number of leaves
  11. int N = Integer.parseInt(firstLine.split(" ")[0]);
  12. ArrayList<Integer> leafNumbers = new ArrayList<Integer>();
  13. for(int i=1;i<=N;i++) {
  14. leafNumbers.add(i);
  15. }
  16. //K is the number of caterpillars
  17. byte K = Byte.parseByte(firstLine.split(" ")[1]);
  18.  
  19. for (byte i=1;i<=K;i++) {
  20. int caterpillarLength = Integer.parseInt(reader.nextLine());
  21. for (int j=1;i<=N;j=j+caterpillarLength) {
  22. if(j <= N) {
  23. leafNumbers.remove((Integer) j);
  24. } else {
  25. break;
  26. }
  27. }
  28. }
  29. reader.close();
  30. //System.out.println(leafNumbers.toString());
  31.  
  32. System.out.println(leafNumbers.size());
  33. }
  34. }
Runtime error #stdin #stdout #stderr 4.99s 380672KB
stdin
1000000000 5
2
2
2
2
2
stdout
Standard output is empty
stderr
/spoj/java_run: line 9: 17329 CPU time limit exceeded /opt/$VER/bin/java -client -Xbatch -Dfile.encoding=UTF-8 -jar tested.zip