**PROBLEM LINK :**

[Contest][1]

**Probelm Code :** UEMP02

**Panel Members**

Problem Setter:[Sintu Kumar][2]

Problem Tester:[Sintu Kumar][3]

Contest Admin:[Sintu Kumar][4]

**DIFFICULTY**:

EASY

**PREREQUISITES**:

Sample,Input Processing , Basic Mathematics,Mathematical Formulation

**PROBLEM:**

In a school there are N student .On the occation of annual function for each Si th

where 1<=i<=N student givent Ti tasks and difference between tasks of two consecutive students are same and (i+1)the student must get more task than ith student.

School have M number of task. Your task is find out whether task distribution is possible or impossible.

**EXPLANATION:**

This is the problem based on arithmetic progression. Using Arithmetic Progression Sum this problem will be solved. Here Given that difference between task of each two consecutive student is same. So, the difference between task will be common difference **D**.

Here it is also mention that (Si+1)th student get more task than Si th student .

So let’s **A** be number of task assigned to 1st student.

2nd will get **A+D** number of task.

3nd will get **A+2*D** number of task.

…

So… on **Nth** Student will get **A+(N-1) D* number of task.

Total number of Task will be = **A** + **A+D** +**A+2*D** +…+**A+(N-1) D*

Total Task = (N/2)*(2*A+(N-1)*D) .

So check for all possible value of A and D. whether Given no of task Match of Not.

if for any combination of A and D match than Task Distribution Possible otherwise Impossible.

**Basic C++ Code:**

int main() {

```
int n,m;
cin>>n>>m;
```

bool isPossible=false;

```
for(int a=1;a<=100;a++){
for(int d=1;d<=100;d++){
long result=(n*(2*a+(n-1)*d))/2;
if(result==m){
isPossible=true;
break;
}
}
if(isPossible)
break;
```

}

if(isPossible)

```
cout<<"possible"<<endl;
```

else

```
cout<<"impossible"<<endl;
```

return 0;

}

**TIME COMPLEXITY**

O(N^2)

**SPACE COMPLEXITY**

O(1)

[1]: https://www.codechef.com/UEMK2016/problems/UEMP02

[2]: https://www.codechef.com/users/sintuuemisp

[3]: https://www.codechef.com/users/sintuuemisp

[4]: https://www.codechef.com/users/sintuuemisp