Skip to content

Commit ce3e10c

Browse files
committed
practice question
1 parent 19a4034 commit ce3e10c

11 files changed

+1558
-0
lines changed

Codechef/Practice/MVALUE.cpp

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
Institute: National Institute of Technology, Uttarakhand
5+
*/
6+
#include <bits/stdc++.h>
7+
#include <ext/pb_ds/assoc_container.hpp>
8+
#include <ext/pb_ds/tree_policy.hpp>
9+
using namespace std;
10+
using namespace __gnu_pbds;
11+
typedef long long ll ;
12+
typedef unsigned long long ull;
13+
typedef vector<ll> vl;
14+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
15+
/* Abbrevations */
16+
#define ff first
17+
#define ss second
18+
#define mp make_pair
19+
#define line cout<<endl;
20+
#define pb push_back
21+
#define Endl "\n"
22+
// loops
23+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
24+
// Some print
25+
#define no cout<<"NO"<<endl;
26+
#define yes cout<<"YES"<<endl;
27+
// sort
28+
#define all(V) (V).begin(),(V).end()
29+
#define srt(V) sort(all(V))
30+
#define srtGreat(V) sort(all(V),greater<ll>())
31+
// some extra
32+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
33+
#define precision(x) cout<<fixed<<setprecision(x);
34+
#define sz(V) ll(V.size())
35+
// template
36+
template <typename T>
37+
T mymax(T x,T y)
38+
{
39+
return (x>y)?x:y;
40+
}
41+
// function
42+
ll power(ll x,ll y,ll mod)
43+
{
44+
ll res=1;
45+
// x=x%mod;
46+
while(y>0)
47+
{
48+
if(y%2==1)
49+
{
50+
res*=x;
51+
// res=res%mod;
52+
}
53+
y/=2; x*=x; // x=x%mod;
54+
}
55+
return res;
56+
}
57+
ll str_to_num(string s)
58+
{
59+
stringstream pk(s);
60+
ll num;
61+
pk>>num;
62+
return num;
63+
}
64+
65+
string num_to_str(ll num)
66+
{
67+
return to_string(num);
68+
}
69+
// datatype definination
70+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
71+
class Point
72+
{
73+
public:
74+
ll x;
75+
ll y;
76+
ll z;
77+
ll getsum()
78+
{
79+
return x+y+z;
80+
}
81+
};
82+
/* ascii value
83+
A=65,Z=90,a=97,z=122
84+
*/
85+
/* --------------------MAIN PROGRAM----------------------------*/
86+
// to run ctrl+b
87+
const ll INF=LONG_MAX;
88+
const ll mod1=1e9+7;
89+
const ll mod2=998244353;
90+
91+
92+
// Techniques
93+
// divide into cases, brute force, pattern finding
94+
// sort, greedy, binary search, two pointer
95+
// transform into graph
96+
97+
ll solve()
98+
{
99+
ll n;
100+
cin>>n;
101+
vl v(n);
102+
forin(v,n);
103+
srt(v);
104+
ll ans=LONG_MIN;
105+
ans = max(ans, (v[0] + 1) * (v[1] - 1) + 1);
106+
ans = max(ans, (v[n - 2] + 1) * (v[n - 1] - 1) + 1);
107+
cout << ans << endl;
108+
return 0;
109+
}
110+
111+
int main()
112+
{
113+
speed;
114+
/* #ifndef ONLINE_JUDGE
115+
freopen("input.txt","r",stdin);
116+
freopen("output.txt","w",stdout);
117+
#endif */
118+
ll TestCase=1;
119+
cin>>TestCase;
120+
while(TestCase--)
121+
{
122+
solve();
123+
}
124+
}
125+
/* -----------------END OF PROGRAM --------------------*/
126+
/*
127+
* stuff you should look before submission
128+
* constraint and time limit
129+
* int overflow
130+
* special test case (n=0||n=1||n=2)
131+
* don't get stuck on one approach if you get wrong answer
132+
*/

Codechef/Practice/STRNO.cpp

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
Institute: National Institute of Technology, Uttarakhand
5+
*/
6+
#include <bits/stdc++.h>
7+
#include <ext/pb_ds/assoc_container.hpp>
8+
#include <ext/pb_ds/tree_policy.hpp>
9+
using namespace std;
10+
using namespace __gnu_pbds;
11+
typedef long long ll ;
12+
typedef unsigned long long ull;
13+
typedef vector<ll> vl;
14+
#define speed cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
15+
/* Abbrevations */
16+
#define ff first
17+
#define ss second
18+
#define mp make_pair
19+
#define line cout<<endl;
20+
#define pb push_back
21+
#define Endl "\n"
22+
// loops
23+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
24+
// Some print
25+
#define no cout<<"NO"<<endl;
26+
#define yes cout<<"YES"<<endl;
27+
// sort
28+
#define all(V) (V).begin(),(V).end()
29+
#define srt(V) sort(all(V))
30+
#define srtGreat(V) sort(all(V),greater<ll>())
31+
// some extra
32+
#define printv(v) for(ll i=0;i<ll(v.size());i++){cout<<v[i]<<" ";} line;
33+
#define precision(x) cout<<fixed<<setprecision(x);
34+
#define sz(V) ll(V.size())
35+
// template
36+
template <typename T>
37+
T mymax(T x,T y)
38+
{
39+
return (x>y)?x:y;
40+
}
41+
// function
42+
ll power(ll x,ll y,ll mod)
43+
{
44+
ll res=1;
45+
// x=x%mod;
46+
while(y>0)
47+
{
48+
if(y%2==1)
49+
{
50+
res*=x;
51+
// res=res%mod;
52+
}
53+
y/=2; x*=x; // x=x%mod;
54+
}
55+
return res;
56+
}
57+
ll str_to_num(string s)
58+
{
59+
stringstream pk(s);
60+
ll num;
61+
pk>>num;
62+
return num;
63+
}
64+
65+
string num_to_str(ll num)
66+
{
67+
return to_string(num);
68+
}
69+
// datatype definination
70+
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
71+
class Point
72+
{
73+
public:
74+
ll x;
75+
ll y;
76+
ll z;
77+
ll getsum()
78+
{
79+
return x+y+z;
80+
}
81+
};
82+
/* ascii value
83+
A=65,Z=90,a=97,z=122
84+
*/
85+
/* --------------------MAIN PROGRAM----------------------------*/
86+
// to run ctrl+b
87+
const ll INF=LONG_MAX;
88+
const ll mod1=1e9+7;
89+
const ll mod2=998244353;
90+
91+
92+
// Techniques
93+
// divide into cases, brute force, pattern finding
94+
// sort, greedy, binary search, two pointer
95+
// transform into graph
96+
97+
ll solve()
98+
{
99+
ll x,k;
100+
cin>>x>>k;
101+
ll count=0;
102+
for(ll i=2;i<=sqrt(x);i++){
103+
if(x%i==0){
104+
while(x%i==0){
105+
x/=i;
106+
count++;
107+
}
108+
}
109+
}
110+
if(x>1){
111+
count++;
112+
}
113+
if(count>=k)
114+
cout<<1<<endl;
115+
else
116+
cout<<0<<endl;
117+
return 0;
118+
}
119+
120+
int main()
121+
{
122+
speed;
123+
/* #ifndef ONLINE_JUDGE
124+
freopen("input.txt","r",stdin);
125+
freopen("output.txt","w",stdout);
126+
#endif */
127+
ll TestCase=1;
128+
cin>>TestCase;
129+
while(TestCase--)
130+
{
131+
solve();
132+
}
133+
}
134+
/* -----------------END OF PROGRAM --------------------*/
135+
/*
136+
* stuff you should look before submission
137+
* constraint and time limit
138+
* int overflow
139+
* special test case (n=0||n=1||n=2)
140+
* don't get stuck on one approach if you get wrong answer
141+
*/

0 commit comments

Comments
 (0)