UVa – 10929 – You Can Say 11

Note: Following is a shortcut for determining whether a number is divisible by 11 or not.  I got it on the internet.

Divisibility by 11:
How to check a number is divisible by 11?
It is very simple, check the number, if the difference of the sum of digits at odd places and the sum of its digits at even places, is either 0 or divisible by 11, then clearly the number is divisible by 11.

Examples:
Is the number 2547039 divisible by 11?
First find the difference between sum of its digits at odd and even places.
(Sum of digits at odd places) – (Sum of digits at even places)
= (9 + 0 + 4 + 2) – (3 + 7 + 5)
= 15 – 15 = 0
The number is 0, so the number 2547039 is divisible by 11.

Is the number 13165648 divisible by 11?
(Sum of digits at odd places) – (Sum of digits at even places)
= (8 + 6 + 6 + 3) – (4 + 5 + 1 + 1)
= 23 – 11 = 12
The number is 12, so the number 13165648 is not divisible by 11.

</pre>
#include <bits/stdc++.h>

using namespace std;

int main()
{

string s;
long long i,sum1,sum2,sum3;
while(cin>>s)
{
if(s=="0")
{
break;
}

sum1=0;
for(i=0; i<s.size(); i+=2)
{
sum1=sum1+(s[i]-'0');
}
sum2=0;
for(i=1; i<s.size(); i+=2)
{
sum2=sum2+(s[i]-'0');
}
sum3=abs(sum1-sum2);
if(sum3==0 || sum3%11==0)
{
cout<<s<<" is a multiple of 11."<<endl;
}
else
{
cout<<s<<" is not a multiple of 11."<<endl;
}

}
return 0;
}
<pre>

 

UVa – 10035 – Primary Arithmatic

#include <bits/stdc++.h>

#define ms(a,b)         memset(a,b,sizeof(a))
#define pb(a)           push_back(a)
#define db              double
#define ft              float
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define sz(x)           x.size()
#define qu              queue
#define pqu             priority_queue
#define vc              vector
#define vi              vector<int>
#define vll             vector<long long>
#define pii             pair<int,int>
#define pis             pair<int,string>
#define psi             pair<string,int>
#define all(x)          x.begin(),x.end()
#define CIN             ios_base::sync_with_stdio(0); cin.tie(0)
#define loop0(i,n)      for(int i=0;i<n;i++)
#define loop1(i,n)      for(int i=1;i<=n;i++)
#define stlloop(x)     for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define gcd(a, b)       __gcd(a, b)
#define lcm(a, b)       ((a)*((b)/gcd(a,b)))
#define case(z,x)       cout<<"Case "<<i<<": "<<x<<endl
#define case(z)         cout<<"Case "<<z<<": "
#define PI              3.14159265358979323846264338328
#define valid(tx,ty)    tx>=0 && tx<r && ty>=0 && ty<c
#define MAX             2000

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

using namespace std;

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

    ll a,b,x,y,sum;
    while(cin>>a>>b)
    {
        if(a==0 && b==0)
        {
            break;
        }
        int carry=0,c=0;
        while(a!=0 || b!=0)
        {
            x=0;
            y=0;
            if(a!=0)
            x=a%10;
            if(b!=0)
            y=b%10;
            sum=x+y+carry;
            a=a/10;
            b=b/10;
            carry=sum/10;
            if(carry>=1)
                c++;
        }
        if(c==0)
        {
            cout<<"No carry operation."<<endl;
        }
        else if(c==1)
        {
            cout<<"1 carry operation."<<endl;
        }
        else
            cout<<c<<" carry operations."<<endl;
    }


    return 0;
}