提出 #9706493


ソースコード 拡げる

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;
map<int, int> enumpr(int n) {
    map<int, int> V;
    for (int i = 2; 1LL*i*i <= n; i++) while (n%i == 0) V[i]++, n /= i;
    if (n>1) V[n]++;
    return V;
}
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, A[10101];
map<int, int> primes[10101];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];
	rep(i, 0, N) primes[i] = enumpr(A[i]);

	map<int, int> allPrimes;
	rep(i, 0, N) fore(p, primes[i]) chmax(allPrimes[p.first], p.second);
	mint lcm = 1;
	fore(p, allPrimes) lcm *= mint(p.first) ^ p.second;

	mint ans = 0;
	rep(i, 0, N) {
		mint b = lcm / mint(A[i]);
		ans += b;
	}
	cout << ans << endl;
}





提出情報

提出日時
問題 E - Flatten
ユーザ hamayanhamayan
言語 C++14 (GCC 5.4.1)
得点 500
コード長 3648 Byte
結果 AC
実行時間 43 ms
メモリ 3072 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 3
AC × 18
セット名 テストケース
Sample sample_01, sample_02, sample_03
All hand_01, hand_02, hand_03, max_01, max_02, max_03, max_04, random_01, random_02, random_03, random_04, random_05, random_06, random_07, random_08, sample_01, sample_02, sample_03
ケース名 結果 実行時間 メモリ
hand_01 AC 2 ms 768 KiB
hand_02 AC 2 ms 768 KiB
hand_03 AC 1 ms 768 KiB
max_01 AC 19 ms 2432 KiB
max_02 AC 43 ms 1664 KiB
max_03 AC 10 ms 2560 KiB
max_04 AC 9 ms 3072 KiB
random_01 AC 2 ms 896 KiB
random_02 AC 10 ms 1664 KiB
random_03 AC 11 ms 1792 KiB
random_04 AC 4 ms 1024 KiB
random_05 AC 14 ms 2048 KiB
random_06 AC 7 ms 1408 KiB
random_07 AC 3 ms 896 KiB
random_08 AC 2 ms 896 KiB
sample_01 AC 2 ms 768 KiB
sample_02 AC 2 ms 768 KiB
sample_03 AC 2 ms 768 KiB