結果

問題 No.186 中華風 (Easy)
ユーザー mbanmban
提出日時 2017-04-16 17:03:22
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,222 bytes
コンパイル時間 4,953 ms
コンパイル使用メモリ 106,332 KB
実行使用メモリ 22,872 KB
最終ジャッジ日時 2023-09-26 09:03:06
合計ジャッジ時間 7,418 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
20,932 KB
testcase_01 AC 61 ms
20,836 KB
testcase_02 AC 62 ms
20,728 KB
testcase_03 AC 58 ms
20,808 KB
testcase_04 AC 67 ms
20,836 KB
testcase_05 AC 67 ms
20,776 KB
testcase_06 AC 73 ms
20,796 KB
testcase_07 AC 69 ms
20,752 KB
testcase_08 AC 78 ms
20,788 KB
testcase_09 AC 79 ms
22,856 KB
testcase_10 AC 76 ms
22,872 KB
testcase_11 AC 84 ms
20,696 KB
testcase_12 AC 65 ms
20,804 KB
testcase_13 AC 66 ms
22,676 KB
testcase_14 AC 68 ms
20,796 KB
testcase_15 AC 60 ms
22,692 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 60 ms
18,704 KB
testcase_19 AC 71 ms
20,880 KB
testcase_20 AC 62 ms
20,668 KB
testcase_21 AC 68 ms
22,824 KB
testcase_22 AC 70 ms
22,772 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Collections;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        new Magatro().Solve();
    }
}

public class Scanner
{
    private StreamReader Sr;

    private string[] S;
    private int Index;
    private const char Separator = ' ';

    public Scanner(Stream stream)
    {
        Index = 0;
        S = new string[0];
        Sr = new StreamReader(stream);
    }

    private string[] Line()
    {
        return Sr.ReadLine().Split(Separator);
    }

    public string Next()
    {
        string result;
        if (Index >= S.Length)
        {
            S = Line();
            Index = 0;
        }
        result = S[Index];
        Index++;
        return result;
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public decimal NextDecimal()
    {
        return decimal.Parse(Next());
    }
    public string[] StringArray(int index = 0)
    {
        Next();
        Index = S.Length;
        return S.Skip(index).ToArray();
    }
    public int[] IntArray(int index = 0)
    {
        return StringArray(index).Select(int.Parse).ToArray();
    }
    public long[] LongArray(int index = 0)
    {
        return StringArray(index).Select(long.Parse).ToArray();
    }
    public bool EndOfStream
    {
        get { return Sr.EndOfStream; }
    }
}

public class Magatro
{
    private int X1, X2, X3, Y1, Y2, Y3;
    long ans;

    private void Scan()
    {
        Scanner scanner = new Scanner(Console.OpenStandardInput());
        X1 = scanner.NextInt();
        Y1 = scanner.NextInt();
        X2 = scanner.NextInt();
        Y2 = scanner.NextInt();
        X3 = scanner.NextInt();
        Y3 = scanner.NextInt();
    }

    public void Solve()
    {
        Scan();
        ans = X1;
        bool flag = false;
        for (long i = 0; i <= Y2; i++)
        {
            long j = ans + Y1 * i;
            if (j % Y2 == X2)
            {
                flag = true;
                ans = j;
                break;
            }
        }
        if (!flag)
        {
            Console.WriteLine(-1);
            return;
        }
        long lcm = LCM(Y1, Y2);
        flag = false;
        for (long i = 0; i <= Y3; i++)
        {
            long j = ans + lcm * i;
            if (j % Y3 == X3)
            {
                flag = true;
                ans = j;
                break;
            }
        }
        if (!flag)
        {
            Console.WriteLine(-1);
            return;
        }
        Console.WriteLine(ans);
    }

    private long LCM(long a, long b)
    {
        return (a * b) / GCD(a, b);
    }

    private long GCD(long a, long b)
    {
        if (a < b)
        {
            Swap(ref a, ref b);
        }
        long r = a % b;
        while (r > 0)
        {
            a = b;
            b = r;
            r = a % b;
        }
        return b;
    }

    private void Swap<T>(ref T a, ref T b)
    {
        T t = a;
        a = b;
        b = t;
    }
}
0