結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー kuuso1kuuso1
提出日時 2016-05-14 00:08:21
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,930 bytes
コンパイル時間 1,035 ms
コンパイル使用メモリ 111,348 KB
実行使用メモリ 28,232 KB
最終ジャッジ日時 2024-04-15 17:39:55
合計ジャッジ時間 26,559 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
25,928 KB
testcase_01 AC 28 ms
23,880 KB
testcase_02 AC 29 ms
24,008 KB
testcase_03 AC 28 ms
23,880 KB
testcase_04 WA -
testcase_05 AC 29 ms
24,136 KB
testcase_06 WA -
testcase_07 AC 30 ms
23,884 KB
testcase_08 AC 29 ms
23,884 KB
testcase_09 AC 30 ms
24,020 KB
testcase_10 AC 28 ms
24,012 KB
testcase_11 AC 29 ms
24,004 KB
testcase_12 AC 30 ms
25,808 KB
testcase_13 AC 29 ms
21,964 KB
testcase_14 AC 29 ms
22,088 KB
testcase_15 AC 31 ms
24,016 KB
testcase_16 AC 29 ms
21,832 KB
testcase_17 AC 29 ms
23,760 KB
testcase_18 AC 29 ms
22,104 KB
testcase_19 AC 30 ms
23,808 KB
testcase_20 WA -
testcase_21 AC 30 ms
25,924 KB
testcase_22 WA -
testcase_23 AC 32 ms
26,056 KB
testcase_24 TLE -
testcase_25 TLE -
testcase_26 AC 29 ms
24,012 KB
testcase_27 AC 29 ms
24,016 KB
testcase_28 AC 40 ms
25,876 KB
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
testcase_36 WA -
testcase_37 TLE -
testcase_38 TLE -
testcase_39 TLE -
testcase_40 TLE -
testcase_41 TLE -
testcase_42 TLE -
testcase_43 TLE -
testcase_44 AC 30 ms
24,004 KB
testcase_45 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int[] Er=new int[100000];
		Er[0]=Er[1]=1;
		for(int i=2;i<100000;i++){
			if(Er[i]==0)for(int j=i+i;j<100000;j+=i)Er[j]=1;
		}
		
		List<long> Prim=new List<long>();
		for(int i=0;i<100000;i++){
			if(Er[i]==0)Prim.Add((long)i);
		}
		
		long ans=0;
		for(int i=0;i<Prim.Count;i++){
			var p=Prim[i];
			long trgt0=(H/p)*p;
			if(trgt0>H || trgt0<L)continue;
			bool chk0=!IsPrime(trgt0);
			for(int j=0;(j<i)&&chk0;j++){
				if((trgt0/p)%Prim[j]==0){chk0=false;break;}
			}
			if(chk0){
				ans=trgt0;
			}
			
			
			for(int t=1;t>=0;t--){
				long trgt1=trgt0-p;
				if(trgt1>H || trgt1<L)continue;
				bool chk1=!IsPrime(trgt1);
				for(int j=0;(j<i)&&chk1;j++){
					if((trgt1/p)%Prim[j]==0){chk1=false;break;}
				}
				if(!chk0 & chk1){
					ans=trgt1;
					break;
				}
				trgt0=trgt1;
				
			}
		
		}
		Console.WriteLine(ans);
		
		
		
		
	}
	long L,H;
	public Sol(){
		var d=rla();
		L=d[0];H=d[1];
	}
	
	static bool IsPrime(long x){
		if(x<=1)return false;
		if(x==2)return true;
		for(long j=3;j*j<=x;j+=2){
			if(x%j==0)return false;
		}
		return true;
	}
	
	
	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}
0