 # EXAM_001 Editorial

Practice

Author: Yogesh Deolalkar
Tester: Ram Agrawal
Editorialist: Prathamesh Sogale

EASY.

Sttring, Math

# PROBLEM:

Ram and Shyam are sitting next to each other, hoping to cheat on an exam. However, the examination board has prepared p different sets of questions (numbered 0 through p−1), which will be distributed to the students in the following way:

The students are assigned roll numbers — pairwise distinct positive integers. If a student’s roll number is r, this student gets the ((r−1)%p)-th set of questions. Obviously, Ram and Shyam can cheat only if they get the same set of questions.

You are given the roll numbers of Ram and Shyam: A and B respectively. Find the number of values of p for which they can cheat, or determine that there is an infinite number of such values.

# SOLUTIONS:

Setter's Solution

t=int(input())
for _ in range(t):
a,b=map(int,input().split())
n=a-b
p=0
if(n<0):
n*=-1
if(n==1):
print(1)
else:
for i in range(1,int(n**0.5)+1):
if(n%i==0):
if(n/i==i):
p+=1
else:
p+=2
print(p)

Tester's Solution

#include
#include<math.h>

using namespace std;

int main()
{
int T;
cin>>T;
while(T–){
int a, b;
cin>>a>>b;
int min = 0;
int max = 0;
int count = 0;
if(a<b){
min = a;
max = b;
}
else{
min = b;
max = a;
}
int k = 1;
int c = max-min;

``````    int d=sqrt(c);

int l = 1;

while(d--){

if(c%l==0){
if(c/l==l){
count++;
}else{
count = count+2;
}
}
l++;
}
cout<<count<<endl;

}
return 0;
``````

}