으엌 도대체 왜때문에 time limit exceed가 뜰까요 ㅠㅠ

marong142 Reply 8 years 28 weeks ago
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int i, j, k=0; int T = sc.nextInt(); int n; int find; for (i=0; i<T; i++){ n = sc.nextInt(); find=sc.nextInt(); int[] box = new int[n+1]; for (j=1; j<=n; j++) box[j] = 0; // 0 is close, 1 is open int student; int number_box; for (student=1; student <= n; student++){ // 사물함번호가 학생번호에 의해 나눠지는 경우, box[number_box]는 짝수/홀수로 바뀜. 짝수면 close, 홀수면 open for (number_box=student; number_box<=n; number_box++){ if (number_box % student == 0) box[number_box]++; } } if (box[find] % 2 == 0) System.out.println("close"); else System.out.println("open"); } } } 이유를 도저히 모르겠네요 ㅜㅜ
cjmp1 Reply 8 years 28 weeks ago
N =100000 인데 지금 작성하신코드는 O (n^3) 인것같습니다? 1억번정도수행하면 1초라고보시면되는데 1000000000000000번도네요
cjmp1 Reply 8 years 28 weeks ago
아 n^2 이네요 그래도 10000000000번도네요