Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXPTREE (JULY 17) [CPP] #197

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion 2017/JULY.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
| [JULY17](https://www.codechef.com/JULY17) | [CHEFSIGN](https://www.codechef.com/JULY17/problems/CHEFSIGN) | ★★ | | [![image](../img/GH.png)](JULY/JULY17/CHEFSIGN/CHEFSIGN.cpp) [![image](../img/CC.png)](https://www.codechef.com/viewsolution/14502863) (100 pts) [![image](../img/AC.png)](#) | | [![image](../img/GH.png)](JULY/JULY17/CHEFSIGN/CHEFSIGN.py) [![image](../img/CC.png)](https://www.codechef.com/viewsolution/14488195) (100 pts) [![image](../img/AC.png)](#) |
| [JULY17](https://www.codechef.com/JULY17) | [CALC](https://www.codechef.com/JULY17/problems/CALC) | ★★★ | [![image](../img/GH.png)](JULY/JULY17/CALC/CALC.c) [![image](../img/CC.png)](https://www.codechef.com/viewsolution/14483078) (100 pts) [![image](../img/AC.png)](#) | [![image](../img/GH.png)](JULY/JULY17/CALC/CALC.cpp) [![image](../img/CC.png)](https://www.codechef.com/viewsolution/14439041) (100 pts) [![image](../img/AC.png)](#) | | [![image](../img/GH.png)](JULY/JULY17/CALC/CALC.py) [![image](../img/CC.png)](https://www.codechef.com/viewsolution/14490655) (100 pts) [![image](../img/AC.png)](#) |
| [JULY17](https://www.codechef.com/JULY17) | [IPCTRAIN](https://www.codechef.com/JULY17/problems/IPCTRAIN) | ★★★ | | [![image](../img/GH.png)](JULY/JULY17/IPCTRAIN/IPCTRAIN.cpp)  [![image](../img/CC.png)](https://www.codechef.com/viewsolution/14431781) (100 pts) [![image](../img/AC.png)](#) | | |
| [JULY17](https://www.codechef.com/JULY17) | [EXPTREE](https://www.codechef.com/JULY17/problems/EXPTREE) | ★★★★ | | | | [![image](../img/GH.png)](JULY/JULY17/EXPTREE/EXPTREE.py)  [![image](../img/CC.png)](https://www.codechef.com/viewsolution/14541593) (100 pts) [![image](../img/AC.png)](#) |
| [JULY17](https://www.codechef.com/JULY17) | [EXPTREE](https://www.codechef.com/JULY17/problems/EXPTREE) | ★★★★ | | [![image](../img/GH.png)](JULY/JULY17/EXPTREE/EXPTREE.cpp)  [![image](../img/CC.png)](https://www.codechef.com/viewsolution/14568032) (100 pts) [![image](../img/AC.png)](#) | | [![image](../img/GH.png)](JULY/JULY17/EXPTREE/EXPTREE.py)  [![image](../img/CC.png)](https://www.codechef.com/viewsolution/14541593) (100 pts) [![image](../img/AC.png)](#) |
| [JULY17](https://www.codechef.com/JULY17) | [PSHTTR](https://www.codechef.com/JULY17/problems/PSHTTR) | ★★★★ | | | | |
| [JULY17](https://www.codechef.com/JULY17) | [TWOCOINS](https://www.codechef.com/JULY17/problems/TWOCOINS) | ★★★★ | | | | |
| [JULY17](https://www.codechef.com/JULY17) | [SRVRS](https://www.codechef.com/JULY17/problems/SRVRS) | ★★★★★ | | | | |
Expand Down
68 changes: 68 additions & 0 deletions 2017/JULY/JULY17/EXPTREE/EXPTREE.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// BY: _nishant0208_
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
#define MAX1 1000000007
#define MAX2 1000000009
#define MAX 100001
//code for EXPTREE
ll MOD;
ll exponent(ll, ll);
ll modinverse(ll);
int main()
{
ll t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
n--;
ll x, y, temp1, temp2;
MOD = MAX1;
x = ((n % MOD) * ((n+1) % MOD)) % MOD;
y = (2*((2*n-1) % MOD)) % MOD;
if(x % 2 == 0 && y % 2 == 0)
{
x /= 2;
y /= 2;
}
if(x % 3 == 0 && y % 3 == 0)
{
x /= 3;
y /= 3;
}
temp1=((x % MOD)*(modinverse(y))) % MOD;
MOD = MAX2;
x = ((n % MOD) * ((n+1) % MOD)) % MOD;
y = (2*((2*n-1) % MOD)) % MOD;
if(x % 2 == 0 && y % 2 == 0)
{
x /= 2;
y /= 2;
}
if(x % 3 == 0 && y % 3 == 0)
{
x /= 3;
y /= 3;
}
temp2=((x % MOD)*(modinverse(y))) % MOD;
cout<<temp1<<" "<<temp2<<"\n";
}
return 0;
}

ll exponent(ll a, ll b)
{
if(b == 0)
return 1;
ll temp = (exponent(a, b/2)) % MOD;
temp = (temp*temp) % MOD;
return (b % 2 == 0)? temp : ((a % MOD)*temp) % MOD;
}

ll modinverse(ll val)
{
return exponent(val, MOD-2);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line at end.

Copy link
Author

@NishantTanwar NishantTanwar Oct 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After which line number?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at the end of file.