Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion c++
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

// updated
#define ff first
#define ss second
#define int long long
Expand Down
30 changes: 30 additions & 0 deletions lucky number
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Python program to check for lucky number

# Returns 1 if n is a lucky number otherwise returns 0
def isLucky(n):
# Function attribute will act as static variable

# just for readability, can be removed and used n instead
next_position = n

if isLucky.counter > n:
return 1
if n % isLucky.counter == 0:
return 0

# Calculate next position of input number
next_position = next_position - next_position / isLucky.counter

isLucky.counter = isLucky.counter + 1

return isLucky(next_position)


# Driver Code

isLucky.counter = 2 # Acts as static variable
x = 5
if isLucky(x):
print x,"is a Lucky number"
else:
print x,"is not a Lucky number"
35 changes: 35 additions & 0 deletions uglynumber
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Python3 code to find nth ugly number

# This function divides a by greatest
# divisible power of b
def maxDivide( a, b ):
while a % b == 0:
a = a / b
return a

# Function to check if a number
# is ugly or not
def isUgly( no ):
no = maxDivide(no, 2)
no = maxDivide(no, 3)
no = maxDivide(no, 5)
return 1 if no == 1 else 0

# Function to get the nth ugly number
def getNthUglyNo( n ):
i = 1
count = 1 # ugly number count

# Check for all integers untill
# ugly count becomes n
while n > count:
i += 1
if isUgly(i):
count += 1
return i

# Driver code to test above functions
no = getNthUglyNo(150)
print("150th ugly no. is ", no)

# This code is contributed by "Sharad_Bhardwaj".