From 35ea31c4632302b0bd0a591aa350597cb1685ff9 Mon Sep 17 00:00:00 2001 From: Mahendra2611 Date: Mon, 21 Oct 2024 18:30:01 +0530 Subject: [PATCH] added solution of potd 19 october 2024 --- october_2024/potd_19_10_2024.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 october_2024/potd_19_10_2024.cpp diff --git a/october_2024/potd_19_10_2024.cpp b/october_2024/potd_19_10_2024.cpp new file mode 100644 index 0000000..ad71f9a --- /dev/null +++ b/october_2024/potd_19_10_2024.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; + + void solve( string &s,int n){ + + while(n--){ + s += "1"; + for(int i = s.size()-2;i>=0;i--){ + int id = s[i]-'0'; + id = 1-id; + s.append(1,id+'0'); + } + } + } + + char findKthBit(int n, int k) { + string s = "0"; + solve(s,n); + return s[k-1]; + } + int main(){ + int n,k; + cin>>n>>k; + char x = findKthBit(n,k); + cout<