Search This Blog

Monday, 22 August 2016

SPOJ - Cards Problem Solution

SPOJ - Cards Problem Solution

Solution:-

#include<bits/stdc++.h>
using namespace std;
#define MAX 1000010
#define MOD 1000007

int dp[MAX];

int main()
{
    for(int i=1;i<=MAX;i++)
        dp[i]=(((((i*2)%MOD)+i-1)%MOD)+dp[i-1])%MOD;

    int tc;
    cin>>tc;
    while(tc--)
    {
        int N;
        cin>>N;
        cout<<dp[N]<<endl;
    }
    return 0;
}


No comments:

Post a Comment