結果

問題 No.577 Prime Powerful Numbers
ユーザー sekiya9311sekiya9311
提出日時 2017-10-14 00:18:57
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,735 bytes
コンパイル時間 917 ms
コンパイル使用メモリ 108,032 KB
実行使用メモリ 23,424 KB
最終ジャッジ日時 2024-04-28 21:57:13
合計ジャッジ時間 4,502 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
using System.Text;
using System.Threading.Tasks;

namespace ProgrammingContest
{
    class MainClass
    {
        Scanner sc;
        static void Main(string[] args)
        {
            //new MainClass().MakeTestCase();
            new MainClass().Solve();
        }

        void MakeTestCase()
        {
            Random rand = new Random();
            string backPath = "..";
            char dirSep = System.IO.Path.DirectorySeparatorChar;
            string inFilePath = backPath + dirSep + backPath + dirSep + "in.txt";
            using (var writer = new System.IO.StreamWriter(inFilePath))
            {
                const int L = 500000;
                writer.WriteLine("{0} {1}", L, L % (rand.Next() % L));
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < L; i++)
                {
                    sb.Append(rand.Next() % 2);
                }
                writer.WriteLine(sb.ToString());
            }
        }

        void Solve()
        {
#if DEBUG
            string backPath = "..";
            char dirSep = System.IO.Path.DirectorySeparatorChar;
            string inFilePath = backPath + dirSep + backPath + dirSep + "in.txt";
            sc = new Scanner(new System.IO.StreamReader(inFilePath));
#else
            sc = new Scanner();
#endif

            int Q = sc.NextInt;
            for (int i = 0; i < Q; i++)
            {
                long N = sc.NextLong;
                long sqrtN = (long) Math.Sqrt(N);
                long diff = N - sqrtN;
                Write(diff > 0 && IsPrime(diff) ? "NO" : "YES");
            }
        }

        void Write(object val)
        {
            Console.WriteLine(val.ToString());
        }
        void Write(string format, params object[] vals)
        {
            Console.WriteLine(format, vals);
        }

        bool IsPrime(long val)
        {
            if (val < 2)
            {
                return false;
            }
            for (long i = 2; i * i <= val; i++)
            {
                if (val % i == 0)
                {
                    return false;
                }
            }
            return true;
        }
    }
    
    class Scanner
    {
        Queue<String> buffer;
        char[] sep;
        System.IO.TextReader reader;
        public Scanner(System.IO.TextReader reader = null)
        {
            this.buffer = new Queue<string>();
            this.sep = new char[] { ' ' };
            this.reader = (reader ?? Console.In);
        }
        private void CheckBuffer()
        {
            if (this.buffer.Count == 0 && this.reader.Peek() >= 0)
            {
                string[] sreArray = this.reader.ReadLine().Split(this.sep);
                foreach (String elStr in sreArray)
                {
                    this.buffer.Enqueue(elStr);
                }
            }
        }

        public String Next
        {
            get
            {
                this.CheckBuffer();
                return this.buffer.Dequeue();
            }
        }

        public int NextInt
        {
            get
            {
                return int.Parse(this.Next);
            }
        }
        public double NextDouble
        {
            get
            {
                return double.Parse(this.Next);
            }
        }

        public long NextLong
        {
            get
            {
                return long.Parse(this.Next);
            }
        }
        public bool IsEmpty
        {
            get
            {
                this.CheckBuffer();
                return this.buffer.Count == 0;
            }
        }
    }
}
0