Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 20bcff7

Browse filesBrowse files
committed
dijkstra algo
1 parent 4908140 commit 20bcff7
Copy full SHA for 20bcff7

35 files changed

+2248
-0
lines changed

‎Best_Approach/Calculating_ncr.cpp

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

‎Best_Approach/factorial_upto_250.cpp

Copy file name to clipboard
+109Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll ;
8+
typedef set<pair<int,int>> spi;
9+
typedef set<pair<ll,ll>> spl;
10+
typedef vector<pair<int,int>> vpi;
11+
typedef vector<int> vi;
12+
typedef vector<ll> vl;
13+
typedef vector<bool> vb;
14+
typedef vector<char> vc;
15+
typedef vector<pair<ll,ll>> vpl;
16+
typedef vector<string> vs;
17+
typedef map<int,int>mi;
18+
typedef map<ll,ll> ml;
19+
typedef set<string> ss;
20+
typedef set<char>sc;
21+
typedef set<int> si;
22+
typedef set<ll> sl;
23+
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
24+
// define values.
25+
#define mod 1000000007
26+
#define phi 1.618
27+
/* Bit-Stuff */
28+
#define get_set_bits(a) (__builtin_popcount(a))
29+
#define get_set_bitsll(a) ( __builtin_popcountll(a))
30+
#define get_trail_zero(a) (__builtin_ctz(a))
31+
#define get_lead_zero(a) (__builtin_clz(a))
32+
#define get_parity(a) (__builtin_parity(a))
33+
/* Abbrevations */
34+
#define ff first
35+
#define ss second
36+
#define mp make_pair
37+
#define line cout<<endl;
38+
#define pb push_back
39+
#define Endl "\n"
40+
// loops
41+
#define loop(i,start,end) for(ll i=ll(start);i<ll(end);i++)
42+
#define loop0(num) for(ll i=0;i<ll(num);i++)
43+
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
44+
// Some print
45+
#define no cout<<"NO"<<endl;
46+
#define yes cout<<"YES"<<endl;
47+
#define cc ll test;cin>>test;while(test--)
48+
// sort
49+
#define all(V) (V).begin(),(V).end()
50+
#define srt(V) sort(all(V))
51+
#define srtGreat(V) sort(all(V),greater<ll>())
52+
// function
53+
54+
ll power(ll x,ll y)
55+
{
56+
ll res=1;
57+
while(y>0)
58+
{
59+
if(y%2==1)res*=x;
60+
y/=2; x*=x;
61+
}
62+
return res;
63+
}
64+
/* ascii value
65+
A=65,Z=90,a=97,z=122
66+
*/
67+
/* -----------------------------------------------------------------------------------*/
68+
ll multiply(ll x,ll res[],ll res_size)
69+
{
70+
ll carry=0;
71+
loop(i,0,res_size)
72+
{
73+
ll prod=res[i]*x+carry;
74+
res[i]=prod%10;
75+
carry=prod/10;
76+
}
77+
while(carry)
78+
{
79+
res[res_size]=carry%10;
80+
carry=carry/10;
81+
res_size++;
82+
}
83+
return res_size;
84+
}
85+
86+
ll factorial(ll n)
87+
{
88+
ll res[500];
89+
res[0]=1;
90+
ll res_size=1;
91+
loop(i,2,n+1)
92+
{
93+
res_size=multiply(i,res,res_size);
94+
}
95+
for(ll i=res_size-1;i>=0;i--)
96+
cout<<res[i];
97+
return 0;
98+
}
99+
100+
int main()
101+
{
102+
//freopen("input.txt"a, "r", stdin);
103+
pan;
104+
ll n;
105+
cin>>n;
106+
cout<<"factorial of given number is : ";
107+
factorial(n);
108+
line;
109+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.