## 10193 - All You Need Is Love

Moderator: Board moderators

abdullah<cse du>
New poster
Posts: 39
Joined: Mon Dec 04, 2006 2:18 pm
Contact:
This is very easy problem. I can say you my method to solve this problem.

1. Find the decimal equavalent for the two binary number.

2.Find the GCD of this two decimal number.

3. If GCD is 1 then print the second condition.

4. Or print the first condition.

oliveralderete
New poster
Posts: 3
Joined: Wed Aug 29, 2007 4:05 am
Contact:

### Re: can someone answer me??

"You can assume that all strings in the input will be valid acording to the rules"
then this kind of input does NOT exist in the input!
justforfun wrote:what is the correct output when input are:
1
1
and
0
0

or is there any special input??
i always got WA....
salu2,
(

New poster
Posts: 7
Joined: Fri Sep 18, 2009 5:15 pm
Location: Dhaka
Contact:

### Re: 10193 - All You Need Is Love

Getting TLE....
can anyone help me to improve the algo???
how can i get decimal from binary more efficiently????
or get gcd ?????

it is really a simple problem ...so these tle are really disappointing me....

my code:{in C}

#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{ long int t,i,s1,s2,p=1,l1,ctr;
char str1[35],str2[35];
scanf("%lld",&t);
getchar();
while(p<=t)
{ gets(str1);
gets(str2);
l1=strlen(str1);
s1=0;
for(i=0,l1-=1;str1;i++,l1--)
{ if(str1=='1')
s1+=pow(2,l1);
}

l1=strlen(str2);
s2=0;
for(i=0,l1-=1;str2;i++,l1--)
{ if(str2=='1')
s2+=pow(2,l1);
}

if(s1<s2)
{ i=s1;
s1=s2;
s2=i;
}
ctr=1;
for(i=2;i<=s2 && ctr;i++)
{ if(s1%i);
else
{ if(s2%i);
else
ctr=0;
}
}
if(ctr)
printf("Pair #%lld: Love is not all you need!\n",p);
else
printf("Pair #%lld: All you need is love!\n",p);

p++;
}
return 0;
}

what should be the output for

1
1

0
0

111
1

111001
0

Learning poster
Posts: 74
Joined: Fri May 08, 2009 5:16 pm

### Re: 10193 - All You Need Is Love

Code: Select all

``````for(i=0,l1-=1;str1[i];i++,l1--)
{ if(str1[i]=='1')
s1+=pow(2,l1);
chnge it to for(i=0;i<strlen(str1);i++) ......
}``````
use manual power function or just multiply by 2 .... built in pow will make trouble sometimes,
it will make a binary no to decimal for(i=0,k=0;i<strlen(str1);i++) k=k*2+str1-48;
make a gcd function and it will be helpful

Code: Select all

``````int gcd(int a,int b)
{
if(b==0) return a;
else return gcd(b,a%b);}``````
when posting a code in forum use

Code: Select all

``  .... [  \code]``

New poster
Posts: 7
Joined: Fri Sep 18, 2009 5:15 pm
Location: Dhaka
Contact:

### Re: 10193 - All You Need Is Love

GOT AC>>>

Thnx for ur help

robinmbstu12
New poster
Posts: 1
Joined: Thu Jan 31, 2013 11:30 am

### Why i WA for my efficient code!

This is my code for 10193. I found that the gcd of binary is same as Decimal.Is it true?? Like that ,the gcd of 24 &27 is 3.And the binary expression of this two decimal is
11000 & 11011.I also found that gcd of 11000 & 11011 is also 3.So why WA for this following code::

#include<stdio.h>
unsigned int Euclid_g_c_d(unsigned int a, unsigned int b){
if(b==0)
return a;
else
return Euclid_g_c_d(b,a%b);
}
int main(){
unsigned int a,b,gcd,T,t;
scanf("%u",&T);
for( t=1;t<=T;t++){
scanf("%u%u",&a,&b);
if(Euclid_g_c_d(a,b)==1)
printf("Pair #%u: Love is not all you need!\n",t);
else
printf("Pair #%u: All you need is love!\n",t);
}
return 0;
}

plz anyone help me.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: Why i WA for my efficient code!

Input:

Code: Select all

``````2
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111111
111111111111111111111111111110``````
Correct output:

Code: Select all

``````Pair #1: All you need is love!
Pair #2: Love is not all you need!``````
Check input and AC output for thousands of problems on uDebug!

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

### Re: 10193 - All You Need Is Love

Here's some input / output I found useful during testing / debugging.

Input:

Code: Select all

``````3
11111111111111
111
111111111111111111111111111111
11
1010
1010``````
AC Output:

Code: Select all

``````Pair #1: Love is not all you need!
Pair #2: All you need is love!
Pair #3: All you need is love!
``````
Check input and AC output for over 7,500 problems on uDebug!