結果

問題 No.847 Divisors of Power
ユーザー wunderkammer2wunderkammer2
提出日時 2020-01-22 23:26:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,857 bytes
コンパイル時間 1,051 ms
コンパイル使用メモリ 100,312 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-23 04:54:34
合計ジャッジ時間 2,761 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 12 ms
4,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 5 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 14 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, ll> P;
const ll MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()



vector<int> sieve(size_t max)
{
    vector<bool> IsPrime(100000 + 1, true);
    vector<int> primes;

    IsPrime[0] = false;
    IsPrime[1] = false;

    for (int i = 2; i * i <= 100000; ++i)
        if (IsPrime[i])
        {
            primes.push_back(i);

            for (int j = 2; i * j <= 100000; ++j)
                IsPrime[i * j] = false;
        }
            

    return primes;
}

ll countFactors(vector<P> list, ll num, int idx, int ub)
{
    //リストを最後まで巡回してもubを越えなかった
    if (idx >= list.size()) return 1;

    ll count = 0;

    auto x = list[idx];

    reple(i, 0, x.second)
    {
        //numは単調増加するため、一度でもubを超えたら終了
        if (num > ub) break;

        //次の素因数へ再帰
        count += countFactors(list, num, idx + 1, ub);

        num *= x.first;
    }

    return count;
}

int main()
{	
	int N, K, M;
	cin >> N >> K >> M;

    auto primes = sieve(N);

    vector<P> counts;

    int x = N;
    for (auto p : primes)
    {
        ll count = 0;

        while (x % p == 0)
        {
            count++;
            x /= p;
        }

        //K乗
        if(count > 0) counts.emplace_back(p, count * K);
    }

    cout << countFactors(counts, 1, 0, M) << endl;

	return 0;
}


0