結果

問題 No.816 Beautiful tuples
ユーザー ひばちひばち
提出日時 2019-04-26 22:44:29
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 66 ms / 1,500 ms
コード長 1,716 bytes
コンパイル時間 1,430 ms
コンパイル使用メモリ 64,540 KB
実行使用メモリ 23,832 KB
最終ジャッジ日時 2023-08-16 15:29:19
合計ジャッジ時間 3,089 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
21,736 KB
testcase_01 AC 64 ms
21,696 KB
testcase_02 AC 66 ms
23,724 KB
testcase_03 AC 63 ms
21,676 KB
testcase_04 AC 66 ms
23,692 KB
testcase_05 AC 65 ms
23,748 KB
testcase_06 AC 64 ms
21,612 KB
testcase_07 AC 63 ms
19,736 KB
testcase_08 AC 64 ms
21,788 KB
testcase_09 AC 64 ms
21,684 KB
testcase_10 AC 64 ms
23,788 KB
testcase_11 AC 64 ms
21,772 KB
testcase_12 AC 64 ms
23,688 KB
testcase_13 AC 65 ms
21,632 KB
testcase_14 AC 65 ms
23,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        //Solve();
        WriteLine(Solve());
    }
    static int Solve()
    {
        var ab = Input.ar;
        var list = new List<int>();
        for(var i=1;i*i<=ab[0]+ab[1];i++)
            if ((ab[0] + ab[1]) % i == 0)
            {
                list.Add(i);
                list.Add((ab[0] + ab[1]) / i);
            }
        list = list.OrderBy(v => v).ToList();
        foreach (var val in list)
        {
            if (ab[0] == val || ab[1] == val) continue;
            if ((ab[0] + val) % ab[1] == 0 && (ab[1] + val) % ab[0] == 0)
                return val;
        }
        return -1;
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] ar2D(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] arL2D(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}
0