Monday, April 03, 2017

UVa 10394 solution (Twine Prime)



UVa 10394 solution 
( Twine Prime )


Link of Problem::
https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1335


SOLIUTION::


SOLIUTION LINK::http://paste.ubuntu.com/24305142/

#include<bits/stdc++.h>
using namespace std;
int mx = 20000007;
char mark[20000007];
void sieve()
{
 mark[0] = mark[1] = 1;           // 1 means not prime
 for(int i = 4; i<mx; i+=2) mark[i] = 1;
 for(int i = 3; i*i<mx; i+=2)
  if(mark[i]==0)                   // i is a prime number
   for(int j = i*i; j<mx; j+=i+i)
    mark[j] = 1;
}


int main()
{
    vector<int>a;
    vector<int>c;
    vector<int>d;
    long long int n;
 sieve();
 for(int l=0; l<=20000000; l++)
    {
        if(mark[l]==0)
        {
            a.push_back(l);
        }
    }
 for(int r=1;r<a.size();r++)
 {
     if((a[r])-a[r-1]==2)
     {
         c.push_back(a[r-1]);   // change
         d.push_back(a[r]);  // change
     }
 }

    while(cin>>n)
    {

        cout<<'('<<c[n-1]<<", "<<d[n-1]<<')'<<endl;
    }
    return 0;
}

Codeforces 791A ( Bear and Big Brother )


Codeforces 791A 
( Bear and Big Brother )



Problem Link:
http://codeforces.com/problemset/problem/791/A
Solution : 

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,i,j,cnt;
    cin>>a>>b;
    cnt=0;
    for(i=1;; i++)
    {
            a=a*3;
            b=b*2;
            cnt++;

        if(a>b)
        {
            break;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

UVa 10079 ( Pizza Cutting )

The ACM-ICPC Live Archive

UVa 10079 ( Pizza Cutting )


10079 Pizza Cutting
When someone calls Ivan lazy, he claims that it is his intelligence that helps him to be so. If his
intelligence allows him to do something at less physical effort, why should he exert more? He also
claims that he always uses his brain and tries to do some work at less effort; this is not his laziness,
rather this is his intellectual smartness.
Once Ivan was asked to cut a pizza into seven pieces to distribute it among
his friends. (Size of the pieces may not be the same. In fact, his piece will be
larger than the others.) He thought a bit, and came to the conclusion that
he can cut it into seven pieces by only three straight cuts through the pizza
with a pizza knife. Accordingly, he cut the pizza in the following way (guess
which one is Ivan’s piece):
One of his friends, who never believed in Ivan’s smartness, was startled
at this intelligence. He thought, if Ivan can do it, why can’t my computer?
So he tried to do a similar (but not exactly as Ivan’s, for Ivan will criticize
him for stealing his idea) job with his computer. He wrote a program that
took the number of straight cuts one makes through the pizza, and output a number representing the

Sunday, April 02, 2017

Codeforces Problem 762A (K-th-divisor)

Codeforces Problem 762A 
(K-th-divisor)


Problem link : 
http://codeforces.com/problemset/problem/762/A

You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist.
Divisor of n is any such natural number, that n can be divided by it without remainder.
Input
The first line contains two integers n and k (1 ≤ n ≤ 10151 ≤ k ≤ 109).
Output

কম্পিউটার প্রোগ্রামিং বই সমস্যা - ২


problem link::
http://cpbook.subeen.com/2012/11/positive-negative.html

soliution::
#include<stdio.h>
int main()
{
    long long int n,b,a,sum=0,total=0;

    scanf("%lld", &n);

    for(b = 1; b<=n; b++)

    {
        scanf("%lld",&a);

        if (a>=0)
        {
            total=total+1;
        }
        else if(a<0)
        {
            sum=sum+1;
        }


    }
    printf("%lld %lld\n",total,sum);
    return 0;
}

UVA Solution Prime words (10924)

  10924 Prime Words  UVA ONLINE JUDGE

#include<stdio.h>
#include<string.h>
#include<math.h>
char str[5000000];
int main()
{

    while(scanf("%s",str)!=EOF)
    {


    int a,b,c,d,e;
    a=strlen(str);
    for(c=0;c<a;c++)
    {
        if(str[c]>='a' && str[c]<='z')
        {
            str[c]=str[c]-96;
        }
       else if(str[c]>='A' && str[c]<='Z')
        {
            str[c]=str[c]-38;
        }
    }
    long long int result=0;
    for(c=0;c<a;c++)
    {
       result+=str[c];
    }

      int nil,bis=0;
      for(nil=1;nil<=sqrt(result);nil++)
      {

          if(result%nil==0)
          {
              bis++;
          }
      }
      if(bis==1)
      {
          printf("It is a prime word.\n");
      }
      else
        printf("It is not a prime word.\n");



}
return 0;
}

Fibonacci

Finding the sum of Fibonacci 
&& 
The series of Fibonacci 

soliution::

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int f[100000],i,T,j,a;

    scanf("%lld", &T);
    for(i=1; i<=T; i++)
    {
        scanf("%lld %lld", &f[0], &f[1]);
        for(j=2; j<100; j++)
        {
            f[j]=f[j-1]+f[j-2];
        }
        int z,b,sum=0;
        scanf("%lld", &b);
        scanf("%lld", &a);
        for(z=b; z<=a; z++)
        {
            sum=sum+f[z-1];
            printf(" %lld\n", f[z-1]);
        }
        printf("sum : %lld\n", sum);
    }
    return 0;
}

Divisor

Divisor Problem
soliution::
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,a,T,j,v;
    scanf("%lld",&T);
    for(i=1; i<=T; i++)
    {
        scanf("%lld", &a);
        for(j=1; j<=sqrt(a); j++)
        {
            if(a%j==0)
            {
                v=a/j;
                if(j==1)
                {
                    printf("%lld",j);
                }
                else
                {
                    printf(" %lld",j);
                }
            }
        }
        for(j=sqrt(a); j>=1; j--)
        {
            if(a%j==0)
            {
                v=a/j;
                if(v==sqrt(a))
                {

                }
                else
                {
                    printf(" %lld",v);
                }
            }
        }
        puts("");
    }
    return 0;
}

UVa Solution 10071 (Back To High School Physics)


The ACM-ICPC Live Archive

UVa 10071
(Back To High School Physics) 



Solution : 

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int v,t,i;
    for(i=1; scanf("%d %d",&v,&t)!=EOF;i++)
    {
    printf("%d\n",v*(t*2));
    }
    return 0;
}

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;
}