forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path(CODECHEF)Hard_Sequence.java
49 lines (43 loc) · 1.1 KB
/
(CODECHEF)Hard_Sequence.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//LINK TO THE PROBLEM
//https://www.codechef.com/NOV19B/problems/HRDSEQ
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
while((t--)!=0)
{
int n=Integer.parseInt(br.readLine());
int a[]=new int[129];
int v[]=new int[256];
int i;
for (i=0;i<256 ;i++ )
{
v[i]=0;
}
a[1]=0;
for(i=2;i<129;i++)
{
if(v[a[i-1]] != 0)
a[i]=(i-1)-v[a[i-1]];
else
a[i]=0;
v[a[i-1]]=i-1;
}
int count=0;
for(i=1;i<=n;i++)
{
if(a[n]==a[i])
count++;
}
System.out.println(count);
}
}
}