QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#78132#2919. Subprimebubble_tWA 230ms58012kbJava11998b2023-02-17 04:49:022023-02-17 04:49:03

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-17 04:49:03]
  • 评测
  • 测评结果:WA
  • 用时:230ms
  • 内存:58012kb
  • [2023-02-17 04:49:02]
  • 提交

answer

import java.util.ArrayList;
import java.util.Scanner;

public class Subprime 
{	
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		
		int l = sc.nextInt();
		int h = sc.nextInt();
		String substr = sc.next();
		int count = 0;
		
		ArrayList<Integer> prime = new ArrayList<>();
		prime.add(2);
		
		int num = 3;
		
		while (prime.size() < h) {
			boolean isPrime = true;
			
			int i = 0;
			int check = prime.get(i);
			
			while (check < Math.sqrt(num)) {
				if (num % check == 0) {
					isPrime = false;
					break;
				}
				i++;
				check = prime.get(i);
			}
			
			if (isPrime == true) {
				prime.add(num);
			}
			
			num += 2;
		}
		
		for (int i = l - 1 ; i < prime.size() ; i++) {
			int temp = prime.get(i);
			String pstr = Integer.toString(temp);
			
			if (pstr.contains(substr)) {
				System.out.println(i + " " + pstr);
				count++;
			}
		}
		
		sc.close();
		System.out.println(count);
	}
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 230ms
memory: 58012kb

input:

1 10000
389

output:

83 389
368 2389
491 3389
853 6389
1073 8389
1714 14389
2030 17389
2335 20389
2692 23893
2693 23899
3230 29389
3321 30389
3670 33893
3901 36389
4141 38903
4142 38917
4143 38921
4144 38923
4145 38933
4146 38953
4147 38959
4148 38971
4149 38977
4150 38993
4375 41389
4612 43891
4662 44389
4754 45389
493...

result:

wrong answer 1st lines differ - expected: '45', found: '83 389'