結果

問題 No.888 約数の総和
ユーザー tomomo2b2
提出日時 2019-10-11 18:06:34
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,261 bytes
コンパイル時間 2,548 ms
コンパイル使用メモリ 111,040 KB
実行使用メモリ 26,360 KB
最終ジャッジ日時 2024-11-25 00:01:39
合計ジャッジ時間 4,176 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Linq;
using System.Collections.Generic;
using System.IO;

class MyClass
{
    public static void Solve()
    {
        var N = long.Parse(Console.ReadLine());
        var exp = new Dictionary<long, long>();
        long sum = 1;
        if (N % 2 == 0)
        {
            exp.Add(2, 0);
            while (N % 2 == 0)
            {
                N /= 2;
                exp[2]++;
            }
        }
        for (long p = 3; p * p <= N; p += 2)
        {
            if (N % p == 0)
            {
                exp.Add(p, 0);
                while (N % p == 0)
                {
                    N /= p;
                    exp[p]++;
                }
            }
        }
        if (N != 1)
        {
            exp.Add(N, 1);
        }
        foreach (var p in exp.Keys)
        {
            long factor = 0;
            for (int i = 0; i <= exp[p]; i++)
            {
                factor += (long)Math.Pow(p, i);
            }
            sum *= factor;
        }
        Console.WriteLine(sum);
    }

    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}
0