# C,C++/JAVA/BASH/ASM ARENA

## वह प्रदीप जो दीख रहा है झिलमिल दूर नही है थक कर बैठ गये क्या भाई मन्जिल दूर नही है चिन्गारी बन गयी लहू की बून्द गिरी जो पग से चमक रहे पीछे मुड देखो चरण-चिनह जगमग से बाकी होश तभी तक, जब तक जलता तूर नही है थक कर बैठ गये क्या भाई मन्जिल दूर नही है अपनी हड्डी की मशाल से हृदय चीरते तम का, सारी रात चले तुम दुख झेलते कुलिश का। एक खेय है शेष, किसी विध पार उसे कर जाओ; वह देखो, उस पार चमकता है मन्दिर प्रियतम का। आकर इतना पास फिरे, वह सच्चा शूर नहीं है; थककर बैठ गये क्या भाई! मंज़िल दूर नहीं है। दिशा दीप्त हो उठी प्राप्त कर पुण्य-प्रकाश तुम्हारा, लिखा जा चुका अनल-अक्षरों में इतिहास तुम्हारा। जिस मिट्टी ने लहू पिया, वह फूल खिलाएगी ही, अम्बर पर घन बन छाएगा ही उच्छ्वास तुम्हारा। और अधिक ले जाँच, देवता इतन क्रूर नहीं है। थककर बैठ गये क्या भाई! मंज़िल दूर नहीं है। ### My misconception about Compound assignment operators in C,C++March 18, 2013

Filed under: Uncategorized — whoami @ 09:41
Tags: , , ,

Today i got cleared of a very big misconception about Compound assignment operators.

I had wrongly understood statements like

A -=b+c as A=A-b+cBut correct is A -=b+c is same as A = A – (b+c)

More explanation can be find here

I have built this wrong concept because in elementary C books there was rarely mentioning of three variables for compound assignment operator examples. Like

The last example(bottom) below i never came through 😦

expression

evaluation

value += increase;

value = value + increase;

a -= 5;

a = a - 5;

a /= b;

a = a / b;

price *= units + 1;

price = price * (units + 1)

Advertisements  ### Check your pointer skills.January 4, 2013

Filed under: Uncategorized — whoami @ 11:47
Tags: , , , ,

Good Evening !!!

Explain the following :-

1. int (*(*foo)(void ))

2.char *const argv[]

3. char * const *argv

4. void (*p) (void (*)() )

Things that you might know well:-

1. const char*

2. char* const

3. const char* const

4. const *char ->tricky

5. char const * -> similar as one of the above(guess which one?)

🙂  ### Modular ExponentiationSeptember 4, 2010

Filed under: C,C++ Programs — whoami @ 18:05
Tags: ,

# Problem5

CodeChef

ACCEPTED

```
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
using namespace std;
int  main()
{
int A,B;
while(1)
{
scanf("%d%d",&A,&B);
if(A==0&&B==0) break;

int base,power,modulus;
modulus=1000000;
base=A;power=B;
long long result = 1;
for (int i = 31; i >= 0; i--) {
result = (result*result) % modulus;
if ((power & (1 << i)) != 0) {
result = (result*base) % modulus;
}
}

int ans=(int) result;

printf("%d\n",ans);
}

return 0;
}

```  ### Programming QuestJune 29, 2010

Filed under: C,C++ Programs — whoami @ 09:02
Tags: , , ,

From YoungProgrammer.com

LCM-GCD based question

Question:

We all interested in mathematics and world are divided in to two parts.
One who are interested in mathematics and other who are afraid of mathematics.
Here is a equation:
( X * N ) % Y = 0

Given two number X & Y you have to find minimum N that satisfies the equation.

### Input:

Input consists of two positive integer X & Y . (1<=X,Y<=2000000000)

### Output:

You have to output minimum N.

```1 5
6 7
```

### Sample Output:

```5
7

Note: You have to give the total of all output for each input.
For the sample input set, you have to give
7+5 = 12. So answer is 12.

Download data sets

ANS-562252
my solution
#include<cstdlib>
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <sstream>
#include <iomanip>
#include <complex>
#include <queue>
#include <functional>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define last(a) int(a.size() - 1)
#define all(a) a.begin(), a.end()
#define seta(a,x) memset (a, x, sizeof (a))
#define I (int)
#define SZ(x) ((int) (x).size())
#define FE(i,x) for(typedef((x).begin() i=(x).begin();i!=(x).end();i++)

typedef long long int  int64;
typedef unsigned long long int uint64;
typedef long double ldb;
typedef pair <int, int> pii;
typedef vector<int>vi;
typedef vector<string>vs;

template <class T> T sqr (T x) {return x * x;}

int gcd(int a,int b)
{
if(b==0) return a;
return gcd(b,a%b);
}

int main()
{
int X,Y;
int total=0;
while(1)
{
cin>>X>>Y;
int hcf=gcd(X,Y);
int lcm=(X*Y)/hcf;
total+=(lcm/X);
cout<<total<<endl;
}

return 0;
}

```  ### Programming Quest

Filed under: C,C++ Programs — whoami @ 08:43
Tags: ,
```If a number is the only number between a prime number and a square number it is
beprisque.
Such few numbers are: 2 3 8 10
2 is beprisque, because, 1 is a square and 3 is a prime number
3 is beprisque, because, 2 is prime and 4 is a square number
What's the 100th beprisque number ?

ANS-119026
From Young programmer.com

my solution (not optimized)

#include<cstdlib>
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <sstream>
#include <iomanip>
#include <complex>
#include <queue>
#include <functional>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define last(a) int(a.size() - 1)
#define all(a) a.begin(), a.end()
#define seta(a,x) memset (a, x, sizeof (a))
#define I (int)
#define SZ(x) ((int) (x).size())
#define FE(i,x) for(typedef((x).begin() i=(x).begin();i!=(x).end();i++)

typedef long long int  int64;
typedef unsigned long long int uint64;
typedef long double ldb;
typedef pair <int, int> pii;
typedef vector<int>vi;
typedef vector<string>vs;

template <class T> T sqr (T x) {return x * x;}

int main()
{
static int prime;
static int sqr;
for(int i=1;i<=1000;i++)
sqr[i*i]=1;

prime=0;prime=1;

for(int i=3;i<=1000000;i=i+2)
{
int flag=1;
for(int j=3;j<=sqrt(i);j++)
{
if(i%j==0) { flag=0;break;}
else continue;
}
if(flag==1) prime[i]=1;
}

int count=0;
for(int i=2;i<=120000;i++)
{
if((sqr[i-1]==1&&prime[i+1]==1)||(sqr[i+1]==1&&prime[i-1]==1)){cout<<i<<endl; ++count;}
}

cout<<count<<endl;

return 0;
}

here is  the few BEPRISQUE number
2
3
8
10
24
48
80
82
168
224
226
360
440
442
728
840
1088
1090
1224
1368
1522
1848
2026
2208
2400
3024
3250
3720
3968
4760
5040
5624
5928
6562
7920
8648
9802
10608
11026
11448
12322
13688
13690
14160
14640
15130
16128
17160
18224
19320
21024
21610
24024
25920
28560
29242
29928
31328
33488
36480
42024
44520
47088
47962
49728
50626
53360
54288
56168
56170
57120
59050
61008
62002
64008
65026
66048
67080
70224
71288
74528
74530
77840
81224
85848
88210
89400
90600
91808
91810
95480
95482
97968
99224
103042
104328
112224
113568
116280
119026
100
```  ### Programming Quest

Filed under: C,C++ Programs — whoami @ 07:09
Tags: ,
```Determine the number of n-bit sequences that contain no adjacent 1’s. For
example, for n = 3 the answer is 5 (sequences 000, 001, 010, 100, 101 are
acceptable while 011, 110, 111 are not).
Find the answer where n = 10

ANS-144

#include<cstdlib>
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <sstream>
#include <iomanip>
#include <complex>
#include <queue>
#include <functional>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define last(a) int(a.size() - 1)
#define all(a) a.begin(), a.end()
#define seta(a,x) memset (a, x, sizeof (a))
#define I (int)
#define SZ(x) ((int) (x).size())
#define FE(i,x) for(typedef((x).begin() i=(x).begin();i!=(x).end();i++)

typedef long long int  int64;
typedef unsigned long long int uint64;
typedef long double ldb;
typedef pair <int, int> pii;
typedef vector<int>vi;
typedef vector<string>vs;

template <class T> T sqr (T x) {return x * x;}

int main()
{
char s;
int count=0;
for(int i=0;i<1024;i++)
{
int tmp=i;
int j=0;
if(i==0) {s='0';s='\0';}
while(tmp>0)
{
int rem=tmp%2;
s[j++]=rem+'0';
tmp=tmp/2;
}
if(i!=0)
s[j]='\0';
//printf("%s\n",s);

if(!strstr(s,"11")) ++count;
}

cout<<count<<endl;

return 0;
}

```  ### Programming Question

Filed under: C,C++ Programs — whoami @ 05:57
Tags:

A number has 6 different digits. If the last digit is moved to the front, then a new number is formed which is exaclty 5 times the old number. With which number did we start?

my solution

```
#include<cstdlib>
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <sstream>
#include <iomanip>
#include <complex>
#include <queue>
#include <functional>

using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define last(a) int(a.size() - 1)
#define all(a) a.begin(), a.end()
#define seta(a,x) memset (a, x, sizeof (a))
#define I (int)
#define SZ(x) ((int) (x).size())
#define FE(i,x) for(typedef((x).begin() i=(x).begin();i!=(x).end();i++)

typedef long long int  int64;
typedef unsigned long long int uint64;
typedef long double ldb;
typedef pair <int, int> pii;
typedef vector<int>vi;
typedef vector<string>vs;

template <class T> T sqr (T x) {return x * x;}

int main()
{
char s;
int count;
for(int i=102345;i<=999999;i++)
{
sprintf(s,"%d",i);
for(int k=0;k<10;k++)
count[k]=0;
int flag=1;
for(int j=0;j<strlen(s);j++){
count[s[j]-'0']++;
if(count[s[j]-'0']>=2) {flag=0;break;}
else continue;
}
if(flag==1)
{
char str;
str=s[strlen(s)-1];
for(int j=0;j<strlen(s)-1;j++)
str[j+1]=s[j];
str[strlen(s)]='\0';
int num=atoi(str);
if(num==5*i) printf("%d\n",i);
}
}
return 0;
}

```

//Answer is 142857 