From 47791dbdaea083cfd3f94dabed3fb16d553e8fba Mon Sep 17 00:00:00 2001 From: damikdhar Date: Fri, 22 Oct 2021 00:54:08 +0530 Subject: [PATCH] Added Kgrammar in cpp --- Contributors.md | 1 + kgrammar.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 kgrammar.cpp diff --git a/Contributors.md b/Contributors.md index 5cbd19b..136388b 100644 --- a/Contributors.md +++ b/Contributors.md @@ -1,3 +1,4 @@ Shag Mittal Ketan Goyal Ashwini Pal +Damik Dhar \ No newline at end of file diff --git a/kgrammar.cpp b/kgrammar.cpp new file mode 100644 index 0000000..da8130b --- /dev/null +++ b/kgrammar.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; +int solve(int n,int k){ + if(n==1 and k==1){ + return 0; + } + int mid=(pow(2,n-1))/2; + if(k<=mid){ + return solve(n-1,k); + } + else{ + return !solve(n-1,k-mid); + } +} +int main() { + int n,k; + cin >> n >> k; + cout<