# Problem 1

### 55 comments on “Problem 1”

• Debangshu

n=int(input(“enter a number: “))
if n%2!=0:
third,first,second,number=0,0,1,0
list=[first,second]
while (number!=(n//2+1)):
third=first+second
list.append(third)
first=second
second=third
number+=1

print(list[n//2+1])
else:
prime_list=[]

for num in range(1, n*n):
# all prime numbers are greater than 1
for i in range(2, num):
if (num % i) == 0:
break
else:
prime_list.append(num)

print(prime_list[n//2])

• c

a=c=1
b=2
n=int(input())
def gen_prime(n):
flag=0
for i in range(2,n//2+1):
if n%i==0:
flag=1
break

else:
return n
if flag==1:
return gen_prime(n+1)

for i in range(n-3):
if i%2==0:
b=gen_prime(b+1)
res=b
else:
a,c=c,a+c
res=c

else:
print(res)

#include

int fibonacci(int n){
int a = 0,b = 1,res;

for(int i = 1;i<=n;i++){
res = a+b;
a = b;
b = res;
}
return a;
}

int prime(int n){
int i,count = 0, num = 1;
while(count<n){
num = num + 1;
for(i=2;i<=num;i++){
if(num%i == 0){
break;
}
}
if(num == i){
count++;
}
}
return num;
}

int main()
{
int n,res;
scanf("%d",&n);

if(n%2 == 1){
res = fibonacci((n/2)+1);
printf("%d",res);
}else{
res = prime(n/2);
printf("%d",res);
}
}

• Akash

Java Code:
import java.util.Scanner;

public class Code10 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();

if(n%2==0){
prime(n/2);
}
else{
fib(n/2 +1);
}

}
public static void fib(int n) {
int n1=0, n2=1, sum=0;
for(int i=1; i0; i++){
flag=0;
for(int j=2; j<i; j++){
if(i%j==0){
flag=1;
break;
}
}
if(flag==0){
count++;
}
if(count==n){
System.out.println(i);
break;
}
}
}

}

• Hemant

def fibbo(n):
n1, n2 = 0, 1
count = 0
if n <= 0:
elif n == 1:
print(n1)
else:
while count < n:
nth = n1 + n2
n1 = n2
n2 = nth
count += 1
print(n1)

def prime(n):
count = 0
for i in range(2, 99999):
flag=0
for j in range(2,i):
if (i % j == 0):
flag=1
break
if flag == 0:
count+=1
if count == n:
print(i)
break

# main
n = int(input())
if n%2 == 1:
fibbo(n//2+1)
else:
prime(n//2)