Monday, April 03, 2017

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


Problem Link:
http://cpbook.subeen.com/2012/11/rectangle-1.html




Solution:

Solution Link: http://paste.ubuntu.com/24305448/

#include<stdio.h>
int main()
{

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

Computer Programming Book

- Problem 03 


Problem link:

http://cpbook.subeen.com/2012/11/count-numbers.html

Solution:

#include<stdio.h>
#include<string.h>
int main()
{

কম্পিউটার প্রোগ্রামিং বই সমস্যা - ১৪,জোড়-বিজোড়-১

link of problem::http://cpbook.subeen.com/2012/11/even-odd-1.html

জোড়-বিজোড় Programming Challenge

ইনপুট

প্রথম লাইনে একটি সংখ্যা থাকবে। সংখ্যাটির মান যত, ততটি লাইনে একটি করে পূর্ণসংখ্যা (0 থেকে 2147483647-এর মধ্যে) দেওয়া থাকবে।

আউটপুট

প্রতিটি পূর্ণসংখ্যার জন্য, সংখ্যাটি জোড় হলে even আর বিজোড় হলে odd প্রিন্ট করতে হবে।

উদাহরণ

ইনপুট:

3
100
0
1111



আউটপুট:

even
even
odd

soliution::

#include<stdio.h>
int main()
{
    int i,n,a[101];
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%2==0 && a[i]>=0)

        {
            printf("even\n");
        }

        else if(a[i]%2!=0 && a[i]>=0)

        {
            printf("odd\n");
        }
    }
    return 0;
}

Some essential functions of C & C++(সি এবং সি++ এর প্রয়োজনীয় ফাংশনসমূহ (বর্ণনা সহ))

সি এবং সি++ এর প্রয়োজনীয় ফাংশনসমূহ (বর্ণনা সহ)
  Function     Description
abs,labs,llabs     computes absolute value of an integer value
fabs     computes absolute value of a floating point value
div,ldiv,lldiv     computes the quotient and remainder of integer division
fmod     remainder of the floating point division operation
remainder     signed remainder of the division operation
remquo     signed remainder as well as the three last bits of the division operation
fma     fused multiply-add operation
fmax     larger of two floating point values
fmin     smaller of two floating point values
fdim     positive difference of two floating point values

nan,nanf,nanl     returns a not-a-number (NaN)

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