結果
| 問題 | No.1747 Many Formulae 2 |
| コンテスト | |
| ユーザー |
bluemegane
|
| 提出日時 | 2021-11-19 22:50:31 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,700 bytes |
| 記録 | |
| コンパイル時間 | 3,221 ms |
| コンパイル使用メモリ | 113,804 KB |
| 実行使用メモリ | 27,612 KB |
| 最終ジャッジ日時 | 2025-01-01 20:56:33 |
| 合計ジャッジ時間 | 2,654 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 RE * 2 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System.Linq;
using static System.Math;
using System.Collections.Generic;
using System;
public class P
{
public string t { get; set; }
public int p { get; set; }
}
public class Hello
{
static void Main()
{
var s = Console.ReadLine().Trim();
getAns(s);
}
static void getAns(string s)
{
var sL = s.Length;
var aa = new List<long>();
var q = new Queue<P>();
var a = "";
q.Enqueue(new P { t = a + s[0], p = 0 });
q.Enqueue(new P { t = a + s[0] + ",", p = 0 });
while (q.Count() > 0)
{
var w = q.Dequeue();
if (w.p == sL-1)
{
string[] line = w.t.Split(',');
var ww = Array.ConvertAll(line, long.Parse).Sum();
aa.Add(ww);
continue;
}
else
{
if (w.p == sL - 2)
{
q.Enqueue(new P { t = w.t + s[w.p + 1], p = w.p + 1 });
}
else
{
q.Enqueue(new P { t = w.t + s[w.p + 1], p = w.p + 1 });
q.Enqueue(new P { t = w.t + s[w.p + 1] + ",", p = w.p + 1 });
}
}
}
var count = 0;
foreach(var x in aa) if (IsPrime(x)) count++;
Console.WriteLine(count);
}
public static bool IsPrime(long n)
{
if (n < 2) return false;
else if (n == 2) return true;
else if (n % 2 == 0) return false;
double sqrtNum = Sqrt(n);
for (int i = 3; i <= sqrtNum; i += 2)
if (n % i == 0) return false;
return true;
}
}
bluemegane