Editorial -CFBDAY

Problem Link - Link

Author - Rishabh Verma
Editorialist - Rishabh Verma

Difficulty :- Easy

Problem -
You have given 3 numbers and problem says you have to add a number at least 1 so that the total sum is a PRIME NUMBER .

Explanation -
Simply make a function which check prime number and in main function run a while loop and take a sum variable and each time add 1 and check if sum is prime . Count how many time the while loop run and print the value of count .

My Solution -

#include <bits/stdc++.h>
using namespace std;
int prim(int n){
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return 0;
        }
    }return 1;
}

int main() {
	int t; cin>>t;
	while(t-->0){
	    int x,y,z; 
	    cin>>x>>y>>z;
	    
	    int ans= x+y+z+1;
	    int count=1;
	    int check=0;
	    while(check != 1){
	        
	         check= prim(ans);
	         if(check) break;
	         else {
	         	ans +=1;
	         	count++;
	         }
	        
	    }cout<<count<<endl;
	}
	return 0;
}