Cod sursa(job #25977)

Utilizator crawlerPuni Andrei Paul crawler Data 4 martie 2007 17:07:47
Problema A+B Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <stdio.h>

#define FOR(i,a,b) for(i=(a);i<=(b);i+=6)

typedef long long lint;

void swap(lint &A,lint &B)
 {
  lint aux = B, aux2 = B;
  
  while(aux)
   ++A, --aux;

  aux = A;
  
  while(aux2)
   --aux, --aux2;

  B = aux;
  aux2=B;

  while(aux2)
   --A, --aux2;
 }

lint split(lint A,lint B);

lint add(lint A,lint B)
 {
  lint i;
  FOR(i,1,A)
   {
    swap(A,B);
    swap(A,B);
   }
   
  if((A == 0)&&(B == 0)) 
   return 0;
     else
  if(B != 0)
   return 1 + add(A,B-1);
    else
   return split(B,A);
 }

lint split(lint A,lint B)
 {
  int aux = (A + B), aux2= aux & 1;
  aux>>=1;
  A=aux;
  B=aux+aux2;
  if(A>0 && B>0)
   return add((A>>1),(B>>1))+add((A>>1)+(A&1),(B>>1)+(B&1));
    else
   return add(A,B);
 }

int main()
{
freopen("adunare.in","r",stdin);
freopen("adunare.out","w",stdout);

lint A,B;

scanf("%d%d", &A,&B);


printf("%d\n", split(A,B));

return 0;
}