ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1000. A+B Problem

Pages: 1 2 3 Next
can you solve this, without using "+"? :)
Posted by Alexander Prudaev 27 Oct 2006 00:26
can you solve this, without using "+"? :)
Re: can you solve this, without using "+"? :)
Posted by Krayev Alexey (PSU) 27 Oct 2006 02:58
-(-a-b)
Re: can you solve this, without using "+"? :)
Posted by Nurbek 21 Dec 2006 23:30
-(-a-b)
BRAVO !!! :)

Edited by author 21.12.2006 23:31
Re: can you solve this, without using "+"? :)
Posted by KIRILL(ArcSTU) 22 Dec 2006 19:00
a--b
a------------------------b  :)))
I can do it without using + and - :-)
Posted by Ostap Korkuna (Lviv NU) 23 Dec 2006 01:43
#include <stdio.h>
#include <math.h>

void main()
{
double a, b;
scanf("%lf%lf", &a, &b);
double c = log(exp(a)*exp(b));
printf("%.0lf", c);
}
Of course!!!
var
  a, b: integer;
begin
  read(a, b);
  asm
    mov ax, a;
    add ax, b;
    mov a, ax;
  end;
  writeln(a);
end.
Or using bitwise operations only :)
Posted by it4.kp 8 Jan 2007 22:13
#include <iostream>

using namespace std;

int sum(int a, int b){
    return (!a||!b ? a|b : sum((a&b)<<1,a^b));
}

int main(){
    int a, b;
    cin >> a >> b;
    cout << sum(a,b);
    return 0;
}
Re: Or using bitwise operations only :)
Posted by Roma Labish[Lviv NU] 8 Jan 2007 22:16
You stole my Idea :) I just think about it, but you write it faster then me :).

Edited by author 08.01.2007 22:17
Re: Or using bitwise operations only :)
Posted by it4.kp 8 Jan 2007 22:26
Ok, let's make problem more interesting...
What is the shortest program to add A and B?

Rules:
1. Whitespace chars are ignored.
2. You cannot use +, -, * and / operations.
3. Assembler is "off the table".
4. Java's BigInteger too
5. any non-integer functions (like log() and exp()) are forbidden

My very raw variant's length is 129:

#include <iostream>

int s(int a, int b){
return (!a||!b ? a|b : s((a&b)<<1,a^b));
}

int main(){
int a, b;
std::cin >> a >> b;
std::cout << s(a,b);
return 0;
}

Edited by author 08.01.2007 22:40
119 )
Posted by RockBeat 8 Jan 2007 23:33
#include<iostream.h>

#define _(x,y)    for(i=1;x&i;y^=i,i<<=1);y^=i;

main(){
    int x,y,i;
    for(cin>>x>>y;y;){_(x,x)_(~y,y)}
    cout<<x;
}
108 )
Posted by it4.kp 8 Jan 2007 23:48
#include <iostream.h>

int s(int a, int b){
return !a||!b ? a|b : s((a&b)<<1,a^b);
}

main(){
int a, b;
cin >> a >> b;
cout << s(a,b);
}

Edited by author 09.01.2007 00:14
106 )
Posted by RockBeat 9 Jan 2007 00:30
#include<iostream.h>

main(){
    int x,y,i;
    for(cin>>x>>y,x=~x;x^~0;x^=y^=x^=y)
        for(y^=i=1;y&i;y^=i<<=1);
    cout<<~y;
}

Edited by author 09.01.2007 01:03
Re: Or using bitwise operations only :)
But with ASM it'll run more quickly!!!
Re: can you solve this, without using "+"? :)
Posted by KIRILL(ArcSTU) 9 Jan 2007 00:40
I've solved it on pascal some time ago, but not post
It's not short of course :)


var
  i,a,b,s,c:integer;
begin
  read(a,b);
  for i:=0 to 31 do
  begin
    s:=s or (a and 1 xor b and 1 xor c) shl i;
    c:=(c and (a and 1 xor b and 1)) or (a and 1 and b and 1);
    a:=a shr 1;
    b:=b shr 1
  end;
 write(s)
end.
Re: Or using bitwise operations only :)
Posted by KIRILL(ArcSTU) 9 Jan 2007 00:42
[SSAU_#617]snipious_#1 aka Pimenov Sergey Nikolaevich wrote 9 January 2007 00:35
But with ASM it'll run more quickly!!!
Compiler generates better assembler code
for a:=a+b than your one
Re: Or using bitwise operations only :)
And what is it??? Try to use 10^10 my code and c:=a+b;!!!
No subject
Posted by Metallllllll 10 Jan 2007 02:01


Edited by author 10.01.2007 02:09
Or using ':=' operator only :)
Posted by Roma Labish[Lviv NU] 10 Jan 2007 02:10
Without :
it4.kp wrote 8 January 2007 22:26
Ok, let's make problem more interesting...
What is the shortest program to add A and B?

Rules:
1. Whitespace chars are ignored.
2. You cannot use +, -, * and / operations.
3. Assembler is "off the table".
4. Java's BigInteger too
5. any non-integer functions (like log() and exp()) are forbidden
and without bitwise operation:) :

63 symbols:

var a,b,i:integer;
begin
read(a,b);
for i:=1 to a do inc(b);
write(b)
end.
Re: Or using ':=' operator only :)
Posted by KIRILL(ArcSTU) 10 Jan 2007 03:07
Tests are simple. You solution pass TL easily, but

for i:=1 to a do inc(b); equal to inc(b,a);
Re: Or using ':=' operator only :)
Posted by Slam [Tartu U] 10 Jan 2007 03:08
inc() is using + itself so its forbidden
Pages: 1 2 3 Next