Problem p02713 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define FI first
#define SE second
#define pb push_back
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(), (c).end()
#define LB lower_bound
#define UB upper_bound
#define max3(a, b, c) max(c, max(a, b))
#define min3(a, b, c) min(c, min(a, b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int ll int
#define OOK order_of_key  // no of elements less than
#define FBO find_by_order // iterator pointing kth element;indexing starts from
                          // 0
#define CK3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl
#define CK4(a, b, c, d)                                                        \\
  cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl

typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
typedef pair<int, pair<int, int>> PIPI;
typedef map<int, int> MII;
typedef vector<int> VI;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int power(int a, int b) {
  int x = 1, y = a;
  while (b > 0) {
    if (b % 2) {
      x = (x * y) % mod;
    }
    y = (y * y) % mod;
    b /= 2;
  }
  return x % mod;
}

// int modInverse(int a, int m) {return power(a, m-2);} //gcd(a,m)=1

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1, T1 = 0; // cin>>T;
  while (T1++ < T) { // cout<<"Case #"<<T1<<": ";

    int n, k;
    cin >> k;
    VI dp(100001, 0);
    n = 3;
    int ans = 0, sum = 0;
    for (int i = k; i >= 1; i--) {
      int x = k / i;
      int mn = (power(x, n) - dp[i] + mod) % mod;
      ans = (ans + mn * i) % mod;
      // sum+=mn;
      // sum%=mod;
      int aa = i;
      for (int i1 = 1; i1 * i1 <= aa; i1++) {
        if (aa % i1 == 0) {
          dp[i1] += mn;
          dp[i1] %= mod;
          if (aa / i1 != i1) {
            dp[aa / i1] += mn;
            dp[aa / i1] %= mod;
          }
        }
      }
    } // cout<<sum<<endl;
    // int ab=(power(k,n)-sum+mod)%mod;
    // ans=(ans+ab)%mod;
    cout << ans << endl;
  }

  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define FI first
#define SE second
#define pb push_back
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(), (c).end()
#define LB lower_bound
#define UB upper_bound
#define max3(a, b, c) max(c, max(a, b))
#define min3(a, b, c) min(c, min(a, b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int ll int
#define OOK order_of_key  // no of elements less than
#define FBO find_by_order // iterator pointing kth element;indexing starts from
                          // 0
#define CK3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl
#define CK4(a, b, c, d)                                                        \\
  cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl

typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
typedef pair<int, pair<int, int>> PIPI;
typedef map<int, int> MII;
typedef vector<int> VI;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int power(int a, int b) {
  int x = 1, y = a;
  while (b > 0) {
    if (b % 2) {
      x = (x * y) % mod;
    }
    y = (y * y) % mod;
    b /= 2;
  }
  return x % mod;
}

// int modInverse(int a, int m) {return power(a, m-2);} //gcd(a,m)=1

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T = 1, T1 = 0; // cin>>T;
  while (T1++ < T) { // cout<<"Case #"<<T1<<": ";

    int n, k;
    cin >> n >> k;
    VI dp(100001, 0);
    int ans = 0, sum = 0;
    for (int i = k; i >= 1; i--) {
      int x = k / i;
      int mn = (power(x, n) - dp[i] + mod) % mod;
      ans = (ans + mn * i) % mod;
      // sum+=mn;
      // sum%=mod;
      int aa = i;
      for (int i1 = 1; i1 * i1 <= aa; i1++) {
        if (aa % i1 == 0) {
          dp[i1] += mn;
          dp[i1] %= mod;
          if (aa / i1 != i1) {
            dp[aa / i1] += mn;
            dp[aa / i1] %= mod;
          }
        }
      }
    } // cout<<sum<<endl;
    // int ab=(power(k,n)-sum+mod)%mod;
    // ans=(ans+ab)%mod;
    cout << ans << endl;
  }

  return 0;
}