結果
| 問題 |
No.395 永遠の17歳
|
| コンテスト | |
| ユーザー |
aketijyuuzou
|
| 提出日時 | 2024-10-13 07:59:36 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 1,000 ms |
| コード長 | 1,954 bytes |
| コンパイル時間 | 1,023 ms |
| コンパイル使用メモリ | 105,344 KB |
| 実行使用メモリ | 17,792 KB |
| 最終ジャッジ日時 | 2024-10-13 07:59:42 |
| 合計ジャッジ時間 | 1,870 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("51");
//44
}
else if (InputPattern == "Input2") {
WillReturn.Add("3");
//-1
//3歳のアイドルは17歳を名乗ることはできません
}
else if (InputPattern == "Input3") {
WillReturn.Add("15");
//8
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
int A = int.Parse(InputList[0]);
int AnswerX = -1;
bool HasAnswer = false;
for (int X = 2; X < int.MaxValue; X++) {
List<int> NumList = DeriveNumList(X, A);
//桁数は進数に対して、単調減少なので、
//2桁未満になったら、17にはならない
if (NumList.Count < 2) break;
if (NumList.Count > 2) continue;
int Keta10 = NumList[0];
int Keta1 = NumList[1];
if (Keta10 != 1) continue;
if (Keta1 != 7) continue;
HasAnswer = true;
AnswerX = X;
}
if (HasAnswer) Console.WriteLine(AnswerX);
else Console.WriteLine(-1);
}
//N進数での数字の並びを返す
static List<int> DeriveNumList(int pShinsuu, int pVal)
{
var WillReturn = new List<int>();
do {
int ModVal = pVal % pShinsuu;
WillReturn.Add(ModVal);
pVal /= pShinsuu;
} while (pVal > 0);
WillReturn.Reverse();
return WillReturn;
}
}
aketijyuuzou