結果
| 問題 |
No.1747 Many Formulae 2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-21 15:25:50 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
AC
|
| 実行時間 | 53 ms / 2,000 ms |
| コード長 | 1,226 bytes |
| コンパイル時間 | 8,218 ms |
| コンパイル使用メモリ | 166,256 KB |
| 実行使用メモリ | 183,280 KB |
| 最終ジャッジ日時 | 2024-06-22 21:52:59 |
| 合計ジャッジ時間 | 9,415 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (101 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System;
namespace Sample
{
class Program
{
static void Main(string[] args)
{
var S = Console.ReadLine();
var N = S.Length;
var count = 0;
for (int i = 0; i < Math.Pow(2, N - 1); i++)
{
long num = 0;
long n = long.Parse(S.Substring(0, 1));
for (int j = 0; j < N - 1; j++)
{
long x = (i >> j) & 1;
if (x == 1)
{
num += n;
n = long.Parse(S.Substring(j + 1, 1));
}
else
{
n = n * 10 + long.Parse(S.Substring(j + 1, 1));
}
}
num += n;
if (num != 1 && isPrime(num)) count++;
}
Console.WriteLine(count);
}
static bool isPrime(long num)
{
for (long i = 2; i <= Math.Sqrt(num); i++)
{
if (num % i == 0)
{
return false;
}
}
return true;
}
}
}