Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions Lucky Numbers
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// C++ program for Lucky Numbers
#include <bits/stdc++.h>
using namespace std;
#define bool int

/* Returns 1 if n is a lucky no.
otherwise returns 0*/
bool isLucky(int n)
{
static int counter = 2;

/*variable next_position is just for
readability of the program we can
remove it and use n only */
int next_position = n;
if(counter > n)
return 1;
if(n % counter == 0)
return 0;

/*calculate next position of input no*/
next_position -= next_position / counter;

counter++;
return isLucky(next_position);
}

// Driver Code
int main()
{
int x = 5;
if( isLucky(x) )
cout << x << " is a lucky no.";
else
cout << x << " is not a lucky no.";
}

// This code is contributed
// by rathbhupendra