Submission #11857819


Source Code Expand

Copy
#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;
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, K;
mint cnt[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> K;

    rrep(g, K, 1) {
        cnt[g] = mint(K / g) ^ N;
        int gg = g * 2;
        while (gg <= K) {
            cnt[g] -= cnt[gg];
            gg += g;
        }
    }

    mint ans = 0;
    rep(g, 1, K + 1) ans += cnt[g] * g;
    cout << ans << endl;
}





Submission Info

Submission Time
Task E - Sum of gcd of Tuples (Hard)
User hamayanhamayan
Language C++ (GCC 9.2.1)
Score 500
Code Size 3398 Byte
Status
Exec Time 13 ms
Memory 4044 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01, sample_02, sample_03
All 500 / 500 hand_01, hand_02, hand_03, hand_04, hand_05, hand_06, random_01, random_02, random_03, random_04, random_05, random_06, random_07, random_08, random_09, random_10, random_11, random_12, random_13, random_14, random_15, sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
hand_01 2 ms 3916 KB
hand_02 7 ms 3976 KB
hand_03 2 ms 3924 KB
hand_04 2 ms 3920 KB
hand_05 2 ms 3976 KB
hand_06 13 ms 3972 KB
random_01 7 ms 3976 KB
random_02 7 ms 3904 KB
random_03 8 ms 3932 KB
random_04 12 ms 3948 KB
random_05 7 ms 3980 KB
random_06 2 ms 4032 KB
random_07 2 ms 4044 KB
random_08 2 ms 3928 KB
random_09 2 ms 3924 KB
random_10 3 ms 4004 KB
random_11 11 ms 3904 KB
random_12 11 ms 3956 KB
random_13 13 ms 3932 KB
random_14 12 ms 4044 KB
random_15 11 ms 3880 KB
sample_01 2 ms 3860 KB
sample_02 2 ms 4000 KB
sample_03 12 ms 3916 KB