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
21 changes: 21 additions & 0 deletions Fibo_sum_last_dig_partial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
m,n = map(int,input().split())
n=(n)%60
if n <= 1:
print(n)

else:

previous = 0
current = 1
sum=1
for i in range(2,n):
previous, current = current, (previous + current)%10
if(n//60>m//60 and m%60>i):
sum+=current

print(sum%10)





18 changes: 18 additions & 0 deletions Fibo_sum_last_digit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
n = int(input())
n=(n)%60
if n <= 1:
print(n)
else:

previous = 0
current = 1
sum=1
for _ in range(n-1):
previous, current = current, (previous + current)%10
sum+=current

print(sum%10)




8 changes: 8 additions & 0 deletions W3 Q1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
n=int(input())
c=0
c+=n//10
n=n%10
c+=n//5
n=n%5
c+=n
print(c)
17 changes: 17 additions & 0 deletions fibo_sqr_sum_lastdig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def last_dig(n):
if (n <= 1):
return n

else:
f=0
s=1
temp=f+s
sum=1
for i in range(1,n):
temp=f+s
f=s
s=temp
sum+=temp*temp
return sum%10
n = int(input())
print(last_dig(n))
16 changes: 16 additions & 0 deletions fibonacci.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Uses python3
def calc_fib(n):
if (n <= 1):
return n

else:
f=0
s=1
temp=f+s
for i in range(1,n):
temp=f+s
f=s
s=temp
return temp
n = int(input())
print(calc_fib(n))
30 changes: 30 additions & 0 deletions fibonacci_huge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Uses python3
import sys
def calc_period(m):
previous = 0
current = 1
p=0
for i in range(m*m):
previous, current = current, previous + current
first = previous % m
sec = current % m
if (first == 0 and sec == 1):
return int(i+1)

def get_fibonacci_huge_naive(n,m):
p=calc_period(m)
n=n%p
if n <= 1:
return n

previous = 0
current = 1

for _ in range(n-1):
previous, current = current, previous + current
return current % m

if __name__ == '__main__':
input = sys.stdin.read()
n, m = map(int, input.split())
print(get_fibonacci_huge_naive(n, m))
16 changes: 16 additions & 0 deletions fibonacci_last_digit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def solution(num):
n=num%60
if n <= 1:
return(n)

previous = 0
current = 1

for _ in range(1,n):
previous, current = current, previous + current

return (current % 10)

if __name__ == "__main__":
inp=int(input())
print(solution(inp))
35 changes: 35 additions & 0 deletions fractional_knapsack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
n,w=map(int,input().split())
ratiolist=[]
values=[]
weights=[]
maxval=0
for _ in range(n) :
v,wt=map(int,input().split())
values.append(v)
weights.append(wt)
r=v/wt
ratiolist.append(r)

while True :
if not ratiolist:
print("{:.4f}".format(maxval))
break
r=max(ratiolist)
pos=ratiolist.index(r)
wt=weights[pos]
v=values[pos]
if(w>=wt):
maxval+=v
weights.pop(pos)
values.pop(pos)
ratiolist.pop(pos)
w=w-wt

elif(w>0) :
fract=w/wt
maxval+=(v*fract)
print("{:.4f}".format(maxval))
break
else:
print("{:.4f}".format(maxval))
break
18 changes: 18 additions & 0 deletions fuel_refiling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
d=int(input())
m=int(input())
n=int(input())
stations=list(map(int,input().split()))
stations.append(d)
minst=0
lastfull=0
flag=0
for station in stations:
if (station - lastfull > m):
print(-1)
flag=1
break
elif (station!=d and stations[stations.index(station)+1]-lastfull>m):
lastfull=station
minst+=1
if flag==0:
print(minst)
13 changes: 13 additions & 0 deletions gcd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

def gcd_naive(a, b):
if a<b:
return gcd_naive(b,a)
elif b==0:
return a
else:
return gcd_naive(b,a%b)

if __name__ == "__main__":

a, b = map(int, input().split())
print(gcd_naive(a, b))
21 changes: 21 additions & 0 deletions lcm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Uses python3
import sys


def gcd(a, b):
if (a < b):
return gcd(b, a)
elif (b == 0):
return a
else:
return gcd(b, a % b)


def lcm_naive(a, b):
return (a * b) / gcd(a, b)


if __name__ == '__main__':
input = sys.stdin.read()
a, b = map(int, input.split())
print(int(lcm_naive(a, b)))