diff --git a/divide and conquer/Modular Exponentation.cpp b/divide and conquer/Modular Exponentation.cpp new file mode 100644 index 0000000..990c47b --- /dev/null +++ b/divide and conquer/Modular Exponentation.cpp @@ -0,0 +1,23 @@ +#include +using namespace std; +int main() { + long long int t;cin>>t; + while(t--) + { + long long int x,y,p,res=1; + cin>>x>>y>>p; + if(x==0) + cout<<"0\n"; + else + { + while(y) + { + if(y%2!=0) + res=(res*x)%p; + y=y/2; + x=(x*x)%p; + } + cout< +using namespace std; + +class Solution{ +public: + int fib(int n){ + if(n==0) + return 0; + else if(n==1 || n==2) + return 1; + else + { + int a[n]; + a[0]=1; + a[1]=1; + for(int i=2;i>t; + while(t--) + { + int N; + cin>>N; + Solution ob; + cout << ob.fib(N) << endl; + } + return 0; +} diff --git a/stack/paranthesisChecker.cpp b/stack/paranthesisChecker.cpp new file mode 100644 index 0000000..7726472 --- /dev/null +++ b/stack/paranthesisChecker.cpp @@ -0,0 +1,74 @@ +/* The famous problem of checking Paranthesis is 'Balanced' or 'Not Balanced' using stacks. +For example, the program should print 'balanced' for exp = “[()]{}{[()()]()}” +and 'not balanced' for exp = “[(])” +*/ + +#include +using namespace std; +int main() { + int t;cin>>t; + while(t--) + { + string n; + cin>>n; + stacks; + int flag=0; + for(int i=0;i