Sunday, April 02, 2017

Codeforces 749A (Bachgold Problem)


Codeforces 749A (Bachgold Problem)



time limit per test-
1 second

memory limit per test-
256 megabytes

input-
standard input

output-
standard output
Bachgold problem is very easy to formulate. Given a positive integer n represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer k is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and k.

UVa Solution 11547 - Automatic Answer


The ACM-ICPC Live Archive

                

                

            11547 - Automatic Answer





Solution : 

#include<bits/stdc++.h>
using namespace std;
int main( )
{
    int n,t,res;
    cin>>t ;
    for (int i=1;i<=t;i++)
    {
        cin>>n;
        res=((((((n*567)/9)+7492)*235)/47)-498);
        cout<<abs((res/10)%10)<<endl;
    }
    return 0;
}


Prime Words UVa 10924 problem




problem link::
https://uva.onlinejudge.org/external/109/10924.pdf




solution::

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    while(cin>>str)
    {
        long long int c=0,sum=0;
        for(int i=0;i<str.size();i++)
        {
            if(islower(str[i]))
            {
                sum+=(str[i]-'a')+1;
            }
            else
            {
                sum+=(str[i]-'A')+27;
            }
        }
        for(int j=2;j<=sqrt(sum);j++)
        {
            if(sum%j==0)
            {
                c=1;
                break;
            }
        }
        if(c==1)
        {
            cout<<"It is not a prime word."<<endl;
        }
        else
        {
            cout<<"It is a prime word."<<endl;
        }
    }
    return 0;
}

UVa Problem Solution 11462



UVa Problem 11462
Age Sort

Problem link:
https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2457



Solution : 


#include<bits/stdc++.h>
using namespace std;

int main()
{
    long int a[2000005],i,n;
    while (scanf("%ld",&n)!=EOF)
    {
        if (n==0)
        {
            break;
        }
        for (i=0;i<n;i++)
        {
            scanf("%ld",&a[i]);
        }
        sort(a,a+n);
        for (i=0;i<n;i++)
        {
            printf("%ld",a[i]);
            if (i<(n-1))
                printf(" ");
        }
        printf("\n");
    }
    return 0;
}

UVa 11332 solution


UVa Problem 11332
Summing Digit

Problem link:
https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2307

Solution :         

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int n,sum;
    while(cin >> n, n != 0)
    {
        if (n<10)
            cout<<n<<endl;
        if (n>9)
        {
            while (n>9)
            {
                sum=0;
                while (n>0 )
                {
                    sum=sum+n%10;
                    n=n/10;
                }
                sum=n+sum;
            }
            cout<<sum<<endl;
        }
    }
    return 0;
}