Problem 15

24 comments on “Problem 15”


  • 348_Amit

    #include
    using namespace std;
    int main() {
    int a,b,c,gcd;
    cin>>a>>b>>c;
    gcd = ( (a>b) ? ((a>c)?a:c) : ((b>c)?b:c) );

    while( (a%gcd != 0) || (b%gcd !=0) || (c%gcd != 0) ) {
    gcd–;
    }
    cout<<gcd;
    }


  • Sajal

    #include
    using namespace std;
    int main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<__gcd(a,__gcd(b,c));
    return 0;
    }


  • Gourav

    num=list(map(int,input().split()))
    dict={}
    for ele in num:
    for i in range (2,ele+1):
    if(ele%i==0):
    if(i in dict.keys()):
    dict[i]+=1
    else:
    dict[i]=1
    max=0
    for ele in dict.keys():
    if(dict[ele]>=len(num)):
    if(max<ele):
    max=ele
    print(max)


  • shushank

    Python
    a=int(input())
    b=int(input())
    c=int(input())
    l1=[]
    d=min(a,b,c)
    for i in range(2,d+1):
    a1=i
    if a%a1==0 and b%a1==0 and c%a1==0:
    l1.append(a1)
    if len(l1)>0:
    print(max(l1))
    else:
    print(“No GCD “)


  • amit

    #include
    #include
    int gretest(int,int,int);
    int main()
    {
    int a,b,c;
    scanf(“%d %d %d”,&a,&b,&c);
    int gcd;
    for(gcd=gretest(a,b,c);gcd>=1;gcd–){
    if((a%gcd==0) && (b%gcd==0) && (c%gcd==0))
    break;
    }
    printf(“%d is the gcd of given numbers”,gcd);
    }
    int gretest(int a,int b,int c)
    {
    if(a>b && a>c)
    return a;
    else if(b>c)
    return b;
    else
    return c;
    }


  • Sunny

    #Python3

    num=[]
    num=list(map(int,input().rstrip().split()))
    num=sorted(num)
    gc=[]
    i=1
    for i in range(1,num[0]+1):
    if (num[0]%i==0) and (num[1]%i==0) and (num[2]%i==0):
    gcd=i

    print(gcd)


  • Raman

    // Online C compiler to run C program online
    #include

    int main() {
    int x,y,z,min,gcd=0,i;

    scanf(“%d”,&x);
    scanf(“%d”,&y);
    scanf(“%d”,&z);

    if(x<y && x<z){
    min=x;
    }
    else if(y<x && y<z){
    min=y;
    }
    else if(z<x && z<y){
    min=z;
    }

    for(i=1;i<=min;i++){
    if(x%i==0 && y%i==0 && z%i==0){
    gcd=i;
    }
    }
    if(gcd==0){
    printf("there is no GCD");
    }
    else{
    printf("GCD is :%d",gcd);
    }
    return 0;
    }


  • rohan

    sir similarly LCM of three numbers
    #include
    int main()
    {
    int i,l,m,x,y,z,max=999999;
    printf(“enter 3 numbers”);
    scanf(“%d%d%d”,&x,&y,&z);
    if(x>y)
    m=x>z?x:z;
    else
    m=y>z?y:z;
    for(i=m;i<=max;++i)
    {
    if(i%x==0 && i%y==0 && i%z==0)
    {l=i;
    break;
    }
    }
    printf("\n%d",l);
    return 0;
    }