Need Help

Правка en1, от saurabhkumarfx, 2020-06-06 23:06:40
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e6 + 10;
const int MOD = 1e9 + 7 , mod = 999998639;
int k[N] , n , p;
int pow_mod(int x , int n , int mod)
{
    int res = 1;
    while(n)
    {
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
signed main()
{
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while(t --)
    {
        cin >> n >> p;
        for(int i = 1 ; i <= n ; i ++) cin >> k[i];
        sort(k + 1 , k + 1 + n , greater<int>());
        int ans1 = 0 , ans2 = 0;
        for(int i = 1 ; i <= n ; i ++)
        {
            if(!ans1 && !ans2) 
                ans1 += pow_mod(p , k[i] , MOD), 
                ans2 += pow_mod(p , k[i] , mod);
            else
                ans1 = (ans1 - pow_mod(p , k[i] , MOD) + MOD) % MOD,
                ans2 = (ans2 - pow_mod(p , k[i] , mod) + mod) % mod;
        }
        cout << ans1 << '\n';
    }
    return 0;
}

Can somebody explain why this solution works for last (DIV2E).It really feels easy to code but what is logic behind another mod ?? https://mirror.codeforces.com/contest/1361/problem/B

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский saurabhkumarfx 2020-06-06 23:06:40 1241 Initial revision (published)