結果

問題 No.2798 Multiple Chain
ユーザー mogura
提出日時 2024-07-09 23:41:29
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 2,386 bytes
コンパイル時間 5,244 ms
コンパイル使用メモリ 232,724 KB
実行使用メモリ 14,016 KB
最終ジャッジ日時 2024-07-09 23:41:38
合計ジャッジ時間 8,424 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 TLE * 1 -- * 1
other -- * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a));
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a),0LL)
using ll=long long;
using ld=long double;
using ull=unsigned long;
ll MOD=998244353;
using mint = static_modint<998244353>;
const int dx[]={0,1,0,-1,1,-1,1,-1};const int dy[]={1,0,-1,0,1,1,-1,-1};
const string ALPHA="ABCDEFGHIJKLMNOPQRSTUVWXYZ";const string alpha="abcdefghijklmnopqrstuvwxyz";
long long gcd(long long a, long long b) {
    while (b != 0) {
        long long temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

// ポラード・ロー法による素因数分解を行う関数
long long pollard_rho(long long n) {
    if (n == 1) return 1;
    if (n % 2 == 0) return 2;

    long long x = rand() % (n - 2) + 2;
    long long y = x;
    long long c = rand() % (n - 1) + 1;
    long long d = 1;

    auto f = [&](long long x) { return (x * x + c) % n; };

    while (d == 1) {
        x = f(x);
        y = f(f(y));
        d = gcd(abs(x - y), n);
        if (d == n) return pollard_rho(n); // 再帰的に呼び出すことで再試行
    }

    return d;
}
bool is_prime(long long n) {
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (long long i = 5; i * i <= n; i += 6) {
        if (n % i == 0 || n % (i + 2) == 0) return false;
    }
    return true;
}
// 素因数分解を行う関数
vector<pair<long long, int>> prime_factors(long long n) {
    vector<pair<long long, int>> factors;

    while (n > 1) {
        if (is_prime(n)) {
            factors.push_back({n, 1});
            break;
        }
        long long factor = pollard_rho(n);
        int count = 0;
        while (n % factor == 0) {
            n /= factor;
            count++;
        }
        if (count > 0) {
            factors.push_back({factor, count});
        }
    }

    return factors;
}
int main(){
  cin.tie(nullptr);
  cout.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  srand(time(0));
  int ans=1;
  vector<pair<long long, int>> factors = prime_factors(n);
    for (int i = 0; i < factors.size(); ++i) {
    	ans*=factors[i].second;
        }
  cout<<ans<<endl;
	
}
0