From cbd1add0cb5dab1bfe0dfd1cda5d53460a975255 Mon Sep 17 00:00:00 2001 From: Nishant Tanwar Date: Tue, 3 Oct 2017 16:05:36 +0530 Subject: [PATCH 1/9] Addded EXPTREE in CPP --- .idea/misc.xml | 4 ++ .idea/vcs.xml | 6 +++ 2017/JULY/JULY17/EXPTREE/EXPTREE.cpp | 68 ++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 2017/JULY/JULY17/EXPTREE/EXPTREE.cpp diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..79b3c94 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp b/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp new file mode 100644 index 0000000..5d26a31 --- /dev/null +++ b/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp @@ -0,0 +1,68 @@ +#include +#include +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() +{ + //your code goes here + ll t; + scanf("%lld", &t); + while(t--) + { + ll n; + scanf("%lld", &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< Date: Tue, 3 Oct 2017 16:10:01 +0530 Subject: [PATCH 2/9] Addded EXPTREE in CPP --- 2017/JULY/JULY17/EXPTREE/EXPTREE.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp b/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp index 5d26a31..8be2b0c 100644 --- a/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp +++ b/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp @@ -1,3 +1,4 @@ +// BY: _nishant0208_ #include #include using namespace std; @@ -65,4 +66,4 @@ ll exponent(ll a, ll b) ll modinverse(ll val) { return exponent(val, MOD-2); -} \ No newline at end of file +} \ No newline at end of file From 9b2c098f3dc507cdbeb6b92cc2c456d8821b38fb Mon Sep 17 00:00:00 2001 From: Nishant Tanwar Date: Tue, 3 Oct 2017 16:21:17 +0530 Subject: [PATCH 3/9] Updated JULY.md with EXPTREE in cpp --- 2017/JULY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/2017/JULY.md b/2017/JULY.md index 9a4c22d..c9f4e1d 100644 --- a/2017/JULY.md +++ b/2017/JULY.md @@ -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) | ★★★★★ | | | | | From 3538411bd9ceb66e82ad81674c4f6517f6e9fe3b Mon Sep 17 00:00:00 2001 From: Nishant Tanwar Date: Tue, 3 Oct 2017 16:42:58 +0530 Subject: [PATCH 4/9] Added proper spaces in EXPTREE.cpp --- 2017/JULY/JULY17/EXPTREE/EXPTREE.cpp | 35 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp b/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp index 8be2b0c..78a4766 100644 --- a/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp +++ b/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp @@ -12,41 +12,40 @@ ll exponent(ll, ll); ll modinverse(ll); int main() { - //your code goes here ll t; - scanf("%lld", &t); + cin>>t; while(t--) { ll n; - scanf("%lld", &n); + cin>>n; n--; ll x, y, temp1, temp2; - MOD=MAX1; + MOD = MAX1; x = ((n % MOD) * ((n+1) % MOD)) % MOD; y = (2*((2*n-1) % MOD)) % MOD; - if(x%2==0 && y%2==0) + if(x % 2 == 0 && y % 2 == 0) { - x/=2; - y/=2; + x /= 2; + y /= 2; } - if(x%3==0 && y%3==0) + if(x % 3 == 0 && y % 3 == 0) { - x/=3; - y/=3; + x /= 3; + y /= 3; } temp1=((x % MOD)*(modinverse(y))) % MOD; - MOD=MAX2; + MOD = MAX2; x = ((n % MOD) * ((n+1) % MOD)) % MOD; y = (2*((2*n-1) % MOD)) % MOD; - if(x%2==0 && y%2==0) + if(x % 2 == 0 && y % 2 == 0) { - x/=2; - y/=2; + x /= 2; + y /= 2; } - if(x%3==0 && y%3==0) + if(x % 3 == 0 && y % 3 == 0) { - x/=3; - y/=3; + x /= 3; + y /= 3; } temp2=((x % MOD)*(modinverse(y))) % MOD; cout< Date: Tue, 3 Oct 2017 16:57:56 +0530 Subject: [PATCH 5/9] Updated EXPTREE.cpp --- 2017/JULY/JULY17/EXPTREE/EXPTREE.cpp | 86 ++++++++++++++-------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp b/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp index 78a4766..a081e59 100644 --- a/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp +++ b/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp @@ -12,57 +12,57 @@ 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) + ll t; + cin>>t; + while(t--) { - x /= 2; - y /= 2; + 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< Date: Fri, 6 Oct 2017 00:35:07 +0530 Subject: [PATCH 6/9] Updated EXPTREE.cpp --- .gitignore | 1 + 2017/JULY/JULY17/CHEFSIGN/CHEFSIGN.cpp | 1 + 2017/JULY/JULY17/EXPTREE/EXPTREE.cpp | 93 ++++++++++++++------------ 3 files changed, 51 insertions(+), 44 deletions(-) diff --git a/.gitignore b/.gitignore index 83f79cb..59c6ec0 100644 --- a/.gitignore +++ b/.gitignore @@ -17,5 +17,6 @@ *.class *.pyc *.html +.idea diff --git a/2017/JULY/JULY17/CHEFSIGN/CHEFSIGN.cpp b/2017/JULY/JULY17/CHEFSIGN/CHEFSIGN.cpp index 7b572d3..65c0f10 100644 --- a/2017/JULY/JULY17/CHEFSIGN/CHEFSIGN.cpp +++ b/2017/JULY/JULY17/CHEFSIGN/CHEFSIGN.cpp @@ -6,6 +6,7 @@ using namespace std; int main() { + std::ios::sync_with_stdio(false); int testCases; cin >> testCases; diff --git a/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp b/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp index a081e59..e5d3c32 100644 --- a/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp +++ b/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp @@ -1,68 +1,73 @@ // BY: _nishant0208_ + #include #include 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--) + +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) { - 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< Date: Fri, 6 Oct 2017 01:23:10 +0530 Subject: [PATCH 7/9] Updated EXPTREE.cpp --- .gitignore | 2 +- 2017/JULY/JULY17/EXPTREE/EXPTREE.cpp | 36 +++++++++++----------------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 59c6ec0..931a5eb 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,6 @@ *.class *.pyc *.html -.idea +.idea/ diff --git a/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp b/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp index e5d3c32..f7208bd 100644 --- a/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp +++ b/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp @@ -15,12 +15,10 @@ ll MOD; ll exponent(ll, ll); ll modinverse(ll); -int main() { - +int main(){ ll t; cin >> t; - while(t--) - { + while(t--){ ll n; cin >> n; n--; @@ -28,13 +26,11 @@ int main() { MOD = MAX1; x = ((n % MOD) * ((n + 1) % MOD)) % MOD; y = (2 * ((2 * n - 1) % MOD)) % MOD; - if(x % 2 == 0 && y % 2 == 0) - { + if(x % 2 == 0 && y % 2 == 0){ x /= 2; y /= 2; } - if(x % 3 == 0 && y % 3 == 0) - { + if(x % 3 == 0 && y % 3 == 0){ x /= 3; y /= 3; } @@ -42,13 +38,11 @@ int main() { MOD = MAX2; x = ((n % MOD) * ((n + 1) % MOD)) % MOD; y = (2 * ((2 * n - 1) % MOD)) % MOD; - if(x % 2 == 0 && y % 2 == 0) - { + if(x % 2 == 0 && y % 2 == 0){ x /= 2; y /= 2; } - if(x % 3 == 0 && y % 3 == 0) - { + if(x % 3 == 0 && y % 3 == 0){ x /= 3; y /= 3; } @@ -58,16 +52,14 @@ int main() { 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 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); +ll modinverse(ll val) { + return exponent(val, MOD - 2); } \ No newline at end of file From e288bf6052823bd9206ad048267a02ce4860f643 Mon Sep 17 00:00:00 2001 From: Nishant Tanwar Date: Wed, 11 Oct 2017 03:57:49 +0530 Subject: [PATCH 8/9] Updated EXPTREE.cpp --- 2017/JULY/JULY17/CHEFSIGN/CHEFSIGN.cpp | 2 -- 2017/JULY/JULY17/EXPTREE/EXPTREE.cpp | 10 +--------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/2017/JULY/JULY17/CHEFSIGN/CHEFSIGN.cpp b/2017/JULY/JULY17/CHEFSIGN/CHEFSIGN.cpp index 65c0f10..f9a9a0d 100644 --- a/2017/JULY/JULY17/CHEFSIGN/CHEFSIGN.cpp +++ b/2017/JULY/JULY17/CHEFSIGN/CHEFSIGN.cpp @@ -5,8 +5,6 @@ using namespace std; int main() { - - std::ios::sync_with_stdio(false); int testCases; cin >> testCases; diff --git a/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp b/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp index f7208bd..a7c4c0f 100644 --- a/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp +++ b/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp @@ -1,20 +1,14 @@ // BY: _nishant0208_ - #include #include using namespace std; typedef long long ll; - #define MAX1 1000000007 - #define MAX2 1000000009 - #define MAX 100001 - ll MOD; ll exponent(ll, ll); ll modinverse(ll); - int main(){ ll t; cin >> t; @@ -51,7 +45,6 @@ int main(){ } return 0; } - ll exponent(ll a, ll b) { if(b == 0) return 1; @@ -59,7 +52,6 @@ ll exponent(ll a, ll b) { temp = (temp * temp) % MOD; return (b % 2 == 0) ? temp : ((a % MOD) * temp) % MOD; } - ll modinverse(ll val) { return exponent(val, MOD - 2); -} \ No newline at end of file +} From 51409beb578825eb121c4a2589b0c3195786ee89 Mon Sep 17 00:00:00 2001 From: Nishant Tanwar Date: Wed, 11 Oct 2017 04:03:45 +0530 Subject: [PATCH 9/9] Updated EXPTREE.cpp --- 2017/JULY/JULY17/EXPTREE/EXPTREE.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp b/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp index a7c4c0f..eaef220 100644 --- a/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp +++ b/2017/JULY/JULY17/EXPTREE/EXPTREE.cpp @@ -55,3 +55,4 @@ ll exponent(ll a, ll b) { ll modinverse(ll val) { return exponent(val, MOD - 2); } +