saurabhkumarfx's blog

By saurabhkumarfx, history, 5 years ago, In English
#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

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By saurabhkumarfx, history, 5 years ago, In English
int  main()
{
     int t;
     cin>>t;
    int a,b,c;
    cin>>a>>b>>c;
    double tmp=a+b;
    tmp=tmp/2;
    cout<<tmp<<"!";
}

input is : 1 232444 123233 232434 why it is giving wrong answer:177838; why it is rounding off the value .

Full text and comments »

  • Vote: I like it
  • -11
  • Vote: I do not like it

By saurabhkumarfx, history, 5 years ago, In English

I am new to codeforces .I always see scoring distribution mentioned of codeforces div-2 and div-1 round.But i want to know what is scoring distribution of div-3 rounds and educational rounds.I want to know if all problems are comprised of same marks?? and late correct submission reduces marks of problems in these div-3 and educational rounds??

Full text and comments »

  • Vote: I like it
  • -19
  • Vote: I do not like it