結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー mbanmban
提出日時 2017-04-12 17:04:01
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 24 ms / 1,000 ms
コード長 1,303 bytes
コンパイル時間 940 ms
コンパイル使用メモリ 104,832 KB
実行使用メモリ 18,048 KB
最終ジャッジ日時 2024-07-18 10:23:06
合計ジャッジ時間 2,786 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 42
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        new Magatro().Solve();
    }
}

public class Magatro
{
    private long H, L;

    private void Scan()
    {
        string[] s = Console.ReadLine().Split(' ');
        H = long.Parse(s[1]);
        L = long.Parse(s[0]);
    }

    public void Solve()
    {
        Scan();
        int iMax = (int)Math.Sqrt(H);
        long max = -1;
        long ans = -1;
        for (long j = iMax; j >= 2; j--)
        {
            if (max > j)
            {
                break;
            }
            for (long i = H / j; i >= j; i--)
            {
                if (i * j < L)
                {
                    break;
                }
                long l = i * j;
                long p = Prime(l);
                if (max < p)
                {
                    max = p;
                    ans = l;
                }
                else if(max == p)
                {
                    ans = Math.Max(ans, l);
                }
            }
        }

        Console.WriteLine(ans);
    }

    private long Prime(long l)
    {
        for (long i = 2; i * i <= l; i++)
        {
            if (l % i == 0) return i;
        }
        return l;
    }
}
0