# Sherlock and Divisors

#codeifyoucansolve
Watson gives an integer N to Sherlock and asks him: What is the number of divisors of N that are divisible by 2?.

Input Format
First line contains T, the number of testcases. This is followed by T lines each containing an integer N.

Output Format
For each testcase, print the required answer in one line.

Constraints
1≤T≤100
1≤N≤109

Sample Input

2
9
8

Sample Output

0
3

Explanation
9 has three divisors 1, 3 and 9 none of which is divisible by 2.
8 has four divisors 1,2,4 and 8, out of which three are divisible by 2.

```import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

public static void main(String[] args) {
try
{
//DataInputStream in = new DataInputStream(System.in);
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while(T>0)
{
int N = sc.nextInt();

if(N%2 == 1)
{
System.out.println('0');
}
else
{
int count=0;
int i=1;
int t =(int) Math.sqrt(N);
while(i<=t)
{
if(N%i == 0)
{
if(i%2 == 0)
count += 1;
int k = N/i;
if((k!=i) && (k%2 == 0))
count += 1;
}
i=i+1;
}
System.out.println(count);
}
}
T = T - 1;
}
catch(Exception e)
{}
}
}```

Compile : http://ideone.com/5jTOAL

# Possible Path

Adam is standing at point (a,b) in an infinite 2D grid. He wants to know if he can reach point (x,y) or not. The only operation he can do is to move to point (a+b,b), (a,a+b), (a-b,b), or (a,a-b) from some point (a,b). It is given that he can move to any point on this 2D grid,i.e., the points having positive or negative X(or Y) co-ordinates.

Tell Adam whether he can reach (x,y) or not.

Input Format
The first line contains an integer, T, followed by T lines, each containing 4 space separated integers i.e. a b x y

Output Format
For each test case, display YES or NO that indicates if Adam can reach (x,y) or not.

Constraints
0 ≤ T ≤ 1000
0 ≤ a,b,x,y ≤ 1018

Sample Input

3
1 1 2 3
2 1 2 3
3 3 1 1

Sample Output

YES
YES
NO

Explanation

(1,1) -> (2,1) -> (2,3).

```import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while(T>0)
{
int a = sc.nextInt();
int b = sc.nextInt();
int x = sc.nextInt();
int y = sc.nextInt();
while(a!=b)
{
if(a>b)
a=a-b;
else
b=b-a;
}
while(x!=y)
{
if(x>y)
x=x-y;
else
y=y-x;
}
if(a==x)
System.out.println("YES") ;
else
System.out.println("NO") ;
T=T-1;
}
}
}
```

Compile : http://ideone.com/3HPJ1Q

# Strange Grid

#codeifyoucansolve
A strange grid has been recovered from an old book. It has 5 columns and infinite number of rows. The bottom row is considered as the first row. First few rows of the grid are like this:

…………..

…………..

20 22 24 26 28

11 13 15 17 19

10 12 14 16 18

1 3 5 7 9

0 2 4 6 8

The grid grows upwards forever!

Your task is to find the integer in cth column in rth row of the grid.

Input Format

There will be two integers r and c separated by a single space.

Constraints

1≤r≤2 * 109

1≤c≤5

Rows are indexed from bottom to top and columns are indexed from left to right.

Output Format

Output the answer in a single line.

Sample Input

6 3

Sample Output

25

Explanation

The number in the 6th row and 3rd column is 25.

```import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger stval;
BigInteger mod = new BigInteger("2");
BigInteger ten = new BigInteger("10");
BigInteger one = new BigInteger("1");

BigInteger bg=new BigInteger(sc.next());
int c;
c=sc.nextInt();
if(bg.remainder(mod).intValue() == 0)
{
bg=bg.subtract(one);
bg=bg.divide(mod);
bg=bg.multiply(ten);
stval = new BigInteger(bg.toString());
}
else
{
bg=bg.divide(mod);
bg=bg.multiply(ten);
stval = new BigInteger(bg.toString());
}
c = (c-1)*2;
String str = String.valueOf(c);
}
}
```

# Linked List representation through JAVA.

class Element
{
Element next;
int num;
public Element(int val)
{
next = null;
num = val;
}
}
{
public void append(int val)
{
Element lastElement = null;
//code for retrive last node
lastElement = null;
else
{
while(tmp.next != null)
{
tmp = tmp.next;
}
lastElement = tmp;
}
if(lastElement == null)
else
lastElement.next = new Element(val);

}
public void printList()
{
System.out.println(“”);
{
while(tmpElement.next != null)
{
System.out.print(tmpElement.num+”->”);
tmpElement = tmpElement.next;
}

}

}
public static void main(String[] args)
{
ll.append(1);
ll.append(2);
ll.append(3);
ll.append(4);
ll.append(5);
ll.append(6);
ll.append(7);
ll.append(8);
ll.append(9);
ll.append(10);
ll.printList();
}
}