JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
* Author : Gaurav Agrawal
* Bugs : Unknown
* Type : Easy challenge 4 practice & timepass
* 🔢Challenge :- Find Nth Term🎓
["S", "L", "SS", "SL", "LS", "LL", "SSS", "SSL", "SLS", "SLL",
"LSS","LSL","LLS","LLL","SSSS","SSSL",.......]
Examples :-
5 : LS
10 : SLL
100 : LSSLSL
1000 : LLLLSLSSL
*/
import java.util.Scanner;
public class GauravProgram{static int j=1;
public static void main(String ... timeSL){
int n=new Scanner(System.in).nextInt(),sp=getSpaces(n),
poss=(int)Math.pow(2,sp),posn=n-poss+2;
System.out.print(getStr(posn,poss,sp));}
static int getSpaces(int n){
return (n-=Math.pow(2,j++))>0?1+getSpaces(n):1;}
static String getStr(int posn,int poss,int sp){
return sp-->=1?((poss/=2)>=posn?"S"+getStr(posn,poss,sp):
"L"+getStr(posn-poss,poss,sp)):"";}
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run