Friday, December 2, 2016

Satisfactory Pairs

Given a positive integer, , find and print the number of pairs of positive integers , where , that exist such that the equation  (where  and  are positive integers) has at least one solution.
Input Format
A single positive integer denoting .
Constraints
Output Format
Print a single integer denoting the number of such pairs.
Sample Input 0
4
Sample Output 0
2
Explanation 0
There are two such  pairs:  and .
NOTE: WRITE YOUR PROGRAM IN COMMENTS SECTION
******************************
PROGRAM
*******************************
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {

    /* Enter your code here. Read input from STDIN. Print output to STDOUT */    
    int n,a,b,x,y,c=0,found;
    scanf("%d",&n);
    for(a=1;a<n;a++)
        {
        for(b=a+1;b<n;b++)
            {
            found=0;
            for(x=1;x<n;x++)
                {
                for(y=1;y<n;y++)
                    {
                    if((a*x+b*y)==n)
                        {
                        c++;
                        found=1;
                        break;
                    }                      
                    
                }
                if(found==1)
                    break;
            }
        }
    }
    printf("%d",c);
    return 0;
}

Contact Geek Placement Preparation

Name

Email *

Message *