Thursday 7 November 2013

PROJECT EULER SOLUTION # 89

Solution to problem number 89 of Project Euler.
Question # 89
 
The rules for writing Roman numerals allow for many ways of writing each number (see About Roman Numerals...). However, there is always a "best" way of writing a particular number.
For example, the following represent all of the legitimate ways of writing the number sixteen:
IIIIIIIIIIIIIIII
VIIIIIIIIIII
VVIIIIII
XIIIIII
VVVI
XVI
The last example being considered the most efficient, as it uses the least number of numerals.
The 11K text file, roman.txt (right click and 'Save Link/Target As...'), contains one thousand numbers written in valid, but not necessarily minimal, Roman numerals; that is, they are arranged in descending units and obey the subtractive pair rule (see About Roman Numerals... for the definitive rules for this problem).
Find the number of characters saved by writing each of these in their minimal form.
Note: You can assume that all the Roman numerals in the file contain no more than four consecutive identical units.

About Roman Numerals:-
Traditional Roman numerals are made up of the following denominations:
I = 1
V = 5
X = 10
L = 50
C = 100
D = 500
M = 1000
You will read about many different rules concerning Roman numerals, but the truth is that the Romans only had one simple rule:
Numerals must be arranged in descending order of size.
For example, three ways that sixteen could be written are XVI, XIIIIII, VVVI; the first being the preferred form as it uses the least number of numerals.
The "descending size" rule was introduced to allow the use of subtractive combinations. For example, four can be written IV because it is one before five. As the rule requires that the numerals be arranged in order of size it should be clear to a reader that the presence of a smaller numeral out of place, so to speak, was unambiguously to be subtracted from the following numeral. For example, nineteen could be written XIX = X + IX (9). Note also how the rule requires X (ten) be placed before IX (nine), and IXX would not be an acceptable configuration.
Generally the Romans tried to use as few numerals as possible when displaying numbers. For this reason, XIX would be the preferred form of nineteen over other valid combinations, like XVIIII or XVIV. However, this was NOT a rule and there still remain in Rome many examples where economy of numerals has not been employed. For example, in the famous Colesseum the the numerals above the forty-ninth entrance is written XXXXVIIII and not IL nor XLIX (see rules below).
Despite this, over time we have continued to introduce new restrictive rules. By mediaeval times it had become standard practice to avoid more than three consecutive identical numerals. That is, IV would be written instead of IIII, IX would be used instead of VIIII, and so on. In addition, the subtractive combinations had the following rules superimposed:
  1. Only I, X, and C can be used as the leading numeral in part of a subtractive pair.
  2. I can only be placed before V and X.
  3. X can only be placed before L and C.
  4. C can only be placed before D and M.
These last four rules are considered to be law, and generally it is preferred, but not necessary, to display numbers using the minimum number of numerals. Which means that IL is considered an invalid way of writing forty-nine, and whereas XXXXVIIII, XXXXIX, XLVIIII, and XLIX are all quite legitimate, the latter is the preferred (minimal) form.
It is also expected that higher denominations should be used whenever possible; for example, L should be used in place of XXXXX, or C should be used in place of LL. However, even this "rule" has been flaunted: in the church of Sant'Agnese fuori le Mura (St Agnes' outside the walls), found in Rome, the date, MCCCCCCVI (1606), is written on the gilded and coffered wooden ceiling; I am sure that many would argue that it should have been written MDCVI.
However, if we believe the adage, "when in Rome do as the Romans do," and we see how the Romans write numerals, then it clearly gives us much more freedom than many would care to admit.


Solution:-
/*************************************************************************/
/*
    solution to project euler 89
*/
#include<string.h>
#include<stdio.h>

int findNumber(char*);
int findRoman(int);

int main()
{
    FILE *fp;
    char str[100];
    int n,i,counter,sum;
    if(fp=fopen("a.txt","r"))
    {
        while(!feof(fp))
        {
            //counter=0;
            i=0;
            fscanf(fp,"%s",str);
            counter=strlen(str);
            str[counter]='\0';
            //printf("%s\n",str);
            sum+=counter-findRoman(findNumber(str));
            str[0]='\0';
        }
        printf("answer = %d\n",sum);
    }
    else
        printf("there was an error in opening the file...aborting...");

    return 0;
}


int findRoman(int n)
{
    int counter=0;
    //printf("%d => ",n);
    while(n>=1000)
    {
        counter++;
        //printf("M");
        n-=1000;
    }
    if(n>=900)
    {
        counter+=2;
        //printf("CM");
        n-=900;
    }
    if(n>=500)
    {
        counter++;
        //printf("D");
        n-=500;
    }
    if(n>=400)
    {
        counter+=2;
        //printf("CD");
        n-=400;
    }
    if(n<400)
        while(n>=100)
        {
            counter++;
            //printf("C");
            n-=100;
        }
    if(n>=90)
    {
        counter+=2;
        //printf("XC");
        n-=90;
    }
    if(n>=50)
    {
        counter++;
        //printf("L");
        n-=50;
    }
    if(n>=40)
    {
        counter+=2;
        //printf("XL");
        n-=40;
    }
    if(n<40)
        while(n>=10)
        {
            counter++;
            //printf("X");
            n-=10;
        }
    if(n==9)
    {
        counter+=2;
        //printf("IX");
        n-=9;
    }
    if(n>=5)
    {
        counter++;
        //printf("V");
        n-=5;
        //printf("%d",n);
    }
    if(n==4)
    {
        counter+=2;
        //printf("IV");
        n-=4;
    }
    while(n!=0)
    {
        counter++;
        //printf("I");
        n--;
        //printf("%d\n",n);
    }
    //printf("\n");
    return counter;
}



int findNumber(char *str)
{
    int i=0,n=0,x;
    for(x=0;x<2;x++)
    {
        if(str[i] && str[i+1] && str[i]=='C' && str[i+1]=='M')
        {
            i+=2;
            n+=900;
        }

        while(str[i] && str[i]=='M')
        {
            n+=1000;
            i++;
        }
    }

    for(x=0;x<2;x++)
    {
        if(str[i] && str[i+1] && str[i]=='C' && str[i+1]=='D')
        {
                i+=2;
                n+=400;
        }

        while(str[i] && str[i]=='D')
        {
                n+=500;
                i++;
        }
    }

    for(x=0;x<2;x++)
    {
        if(str[i] && str[i+1] && str[i]=='X' && str[i+1]=='C')
        {
                i+=2;
                n+=90;
        }

        while(str[i] && str[i]=='C')
        {
                n+=100;
                i++;
        }
    }

    for(x=0;x<2;x++)
    {
        if(str[i] && str[i+1] && str[i]=='X' && str[i+1]=='L')
        {
                i+=2;
                n+=40;
        }

        while(str[i] && str[i]=='L')
        {
                n+=50;
                i++;
        }
    }

    for(x=0;x<2;x++)
    {
        if(str[i] && str[i+1] && str[i]=='I' && str[i+1]=='X')
        {
                i+=2;
                n+=9;
        }

        while(str[i] && str[i]=='X')
        {
                n+=10;
                i++;
        }
    }

    for(x=0;x<2;x++)
    {
        if(str[i] && str[i+1] && str[i]=='I' && str[i+1]=='V')
        {
                i+=2;
                n+=4;
        }

        while(str[i] && str[i]=='V')
        {
                n+=5;
                i++;
        }
    }

    while(str[i] && str[i]=='I')
    {
        n++;
        i++;
    }

    return n;
}
/*************************************************************************/

 

Wednesday 6 November 2013

PROJECT EULER SOLUTION # 65

Solution to problem number 65 of Project Euler
Question # 65
The square root of 2 can be written as an infinite continued fraction.
√2 = 1 +
1
  2 +
1
    2 +
1
      2 +
1
        2 + ...
The infinite continued fraction can be written, √2 = [1;(2)], (2) indicates that 2 repeats ad infinitum. In a similar way, √23 = [4;(1,3,1,8)].
It turns out that the sequence of partial values of continued fractions for square roots provide the best rational approximations. Let us consider the convergents for √2.
1 +
1
= 3/2
 
2
 
1 +
1
= 7/5
  2 +
1
   
2
 
1 +
1
= 17/12
  2 +
1
 
    2 +
1
 
     
2
 
1 +
1
= 41/29
  2 +
1
    2 +
1
 
      2 +
1
 
       
2
 
Hence the sequence of the first ten convergents for √2 are:
1, 3/2, 7/5, 17/12, 41/29, 99/70, 239/169, 577/408, 1393/985, 3363/2378, ...
What is most surprising is that the important mathematical constant,
e = [2; 1,2,1, 1,4,1, 1,6,1 , ... , 1,2k,1, ...].
The first ten terms in the sequence of convergents for e are:
2, 3, 8/3, 11/4, 19/7, 87/32, 106/39, 193/71, 1264/465, 1457/536, ...
The sum of digits in the numerator of the 10th convergent is 1+4+5+7=17.
Find the sum of digits in the numerator of the 100th convergent of the continued fraction for e.

Solution:-

/****************************************************************************/
#include<stdio.h>
#include<stdlib.h>
#define max 100
int n[max]={0},pn[max]={0};
void fun(int);
void print(int*);
void assignArray(int*,int*);
void add(int*,int*);

int main()
{
    int i,sum=0;
    for(i=1;i<=100;i++)
    {
        fun(i);
        /*
        printf("i=%d=>",i);
        print(n);
        */
    }
    for(i=0;i<max;i++)
        sum+=n[i];
    printf("answer = %d\n",sum);
    return 0;
}

void print(int *arr)
{
    int flag=0,i;
    for(i=0;i<max;i++)
    {
        if(arr[i] || flag)
        {
            flag=1;
            printf("%d",arr[i]);
        }
    }
    printf("\n");
}

void add(int*a,int*b)
{
    int i;
    for(i=max-1;i>0;i--)
    {
        a[i]+=b[i];
        if(a[i]>9)
        {
            a[i]%=10;
            a[i-1]+=1;
        }
    }
}

void assignArray(int*a,int*b)
{
    int i;
    for(i=0;i<max;i++)
        a[i]=b[i];
}

void fun(int x)
{
    long long int flag;
    int i,tmpn[max]={0},tmpArr[max]={0};
    if(x==1)
    {
        n[max-1]=2;
        return;
    }
    if(x==2)
    {
        pn[max-1]=2;
        n[max-1]=3;
        return;
    }

    if(x%3==0)
    {
        assignArray(tmpn,n);
        flag=(x/3)*2;
   
        for(i=0;i<flag;i++)
            add(tmpArr,n);

        add(tmpArr,pn);
        assignArray(n,tmpArr);

        assignArray(pn,tmpn);
        return;
    }

    assignArray(tmpn,n);
    add(n,pn);
    assignArray(pn,tmpn);
}

/****************************************************************************/

Saturday 2 November 2013

PROJECT EULER SOLUTION # 29


Solution to problem number 29 of Project Euler
Question # 29
Consider all integer combinations of ab for 2 ≤a ≤5 and 2 ≤b ≤5:
22=4, 23=8, 24=16, 25=32
32=9, 33=27, 34=81, 35=243
42=16, 43=64, 44=256, 45=1024
52=25, 53=125, 54=625, 55=3125
If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 distinct terms:
4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125
How many distinct terms are in the sequence generated by ab for 2 ≤a ≤100 and 2 ≤b ≤100?

Solution # 29
/****************************************************************/
#include<stdio.h>
#include<math.h>

int a,b;

struct pair
{
      int x,y;
};

struct pair p[9801];
int isEqual(int,int);
void setToBasic(int);
int main()
{
      int i,j,counter=0,answer;
      for(i=2;i<=100;i++)
            for(j=2;j<=100;j++)
            {
                  p[counter].x=i;
                  p[counter].y=j;
                  counter++;
            }

      for(i=0;i<9801;i++)
            setToBasic(i);

      answer=9801;

      for(i=9800;i>=0;i--)
            for(j=i-1;j>=0;j--)
                  if(p[i].x && p[i].y && isEqual(i,j))
                        answer--;

      printf("answer = %d\n",answer);
      return 0;
}

int isEqual(int i,int j)
{
      if(p[i].x==p[j].x && p[i].y==p[j].y)
      {
            p[j].x=p[j].y=0;
            return 1;
      }
      return 0;
}

void setToBasic(int counter)
{
      int i,j;
      for(i=2;i<p[counter].x;i++)
            for(j=2;pow(i,j)<=p[counter].x;j++)
                  if(pow(i,j)==p[counter].x)
                  {
                        p[counter].x=i;
                        p[counter].y*=j;
                  }
}
/****************************************************************/

Friday 1 November 2013

Maxim and Dividers - Solution



Maxim likes dividers of the numbers. Also Maxim is fond of lucky numbers of small elephant from Lviv city.

If you remember, lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky, 5, 17, 467 — aren't.

Now Maxim is interested in the next information: what is the number of the integer positive dividers of number n, which are overlucky.

We call number overlucky if it is possible to remove some, but not all, digits and during bonding the remaining digits we will receive a lucky number. For example, number 72344 — overlucky, because it is possible to remove digits 2 and 3, and get number 744, which is lucky. Number 223 isn't overlucky.

Input

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. Single line of each test case contains an integer n.

Output

For each test case on different lines print the answer to the problem.

Constraints

  • 1T10
  • 1 ≤ n ≤ 10^9

Example

Input:
10
1
2
3
4
5
6
7
8
9
10
 
Output:
0
0
0
1
0
0
1
1
0
0
 

Solution:

#include<stdio.h>
 
int isOverLucky(int);
int fun(int);
int main()
{
        int i,t,num,j;
        scanf("%d",&t);
        for(i=0;i<t;i++)
        {
               scanf("%d",&num);
               printf("%d\n",fun(num));
        }
        return 0;
}
 
int isOverLucky(int n)
{
        while(n)
        {
               if(n%10==4 || n%10==7)
                       return 1;
               n/=10;
        }
 
        return 0;
}
 
int fun(int n)
{
        int i,counter=0;
        for(i=1;i*i<n;i++)
               if(n%i==0)
                       counter+=isOverLucky(i)+isOverLucky(n/i);
        if(n%i==0)
               counter+=isOverLucky(i);
        return counter;
}

Small Factorials - Solution


Problem Statement:
You are asked to calculate factorials of some small positive integers.

Input


An integer t, 1<=t<=100, denoting the number of testcases, followed by t lines, each containing a single integer n, 1<=n<=100.

Output


For each integer n given at input, display a line with the value of n!

Example

Sample input:
4
1
2
5
3
Sample output:
1
2
120
6

Solution:

#include<stdio.h>
#include<stdlib.h>
 
void factorial(int*,int);
void print(int*);
void add(int*,int*);
 
int main()
{
        int arr[200]={0},i,t,n,j;
        scanf("%d",&t);
        for(i=0;i<t;i++)
        {
               for(j=0;j<200;j++)
                       arr[j]=0;
               scanf("%d",&n);
               factorial(arr,n);
               print(arr);
               printf("\n");
        }
        return 0;
}
 
void factorial(int *arr,int n)
{
        int tmparr[200]={0};
        int i,j;
        arr[199]=1;
        for(i=1;i<=n;i++)
        {
               for(j=0;j<200;j++)
                       tmparr[j]=0;
               for(j=0;j<i;j++)
               {
                       add(arr,tmparr);
               }
               for(j=0;j<200;j++)
                       arr[j]=tmparr[j];
        }
}
 
void add(int*arr,int*tmparr)
{
        int i;
        for(i=199;i>0;i--)
        {
               tmparr[i]+=arr[i];
               if(tmparr[i]>9)
               {
                       tmparr[i-1]+=1;
                       tmparr[i]%=10;
               }
        }
}
 
void print(int*arr)
{
        int i,flag=0;
        for(i=0;i<200;i++)
        {
               if(arr[i]!=0 || flag)
               {
                       flag=1;
                       printf("%d",arr[i]);
               }
        }
}

Holes in the text - Solution


Problem Statement:
Chef wrote some text on a piece of paper and now he wants to know how many holes are in the text. What is a hole? If you think of the paper as the plane and a letter as a curve on the plane, then each letter divides the plane into regions. For example letters "A", "D", "O", "P", "R" divide the plane into two regions so we say these letters each have one hole. Similarly, letter "B" has two holes and letters such as "C", "E", "F", "K" have no holes. We say that the number of holes in the text is equal to the total number of holes in the letters of the text. Help Chef to determine how many holes are in the text.

Input

The first line contains a single integer T <= 40, the number of test cases. T test cases follow. The only line of each test case contains a non-empty text composed only of uppercase letters of English alphabet. The length of the text is less then 100. There are no any spaces in the input.

Output

For each test case, output a single line containing the number of holes in the corresponding text.

Example

Input:
2
CODECHEF
DRINKEATCODE
 
Output:
2
5

Solution:
#include<stdio.h>
int countHoles(char*);
int arr[26]={0};
int main()
{
        int t,i;
        char str[100];
        arr[0]=1;
        arr[1]=2;
        arr[3]=1;
        arr[14]=1;
        arr[15]=1;
        arr[16]=1;
        arr[17]=1;
 
        scanf("%d",&t);
        for(i=0;i<t;i++)
        {
               scanf("%s",str);
               printf("%d\n",countHoles(str));
        }
        return 0;
}
 
int countHoles(char*str)
{
        int counter=0,i;
        for(i=0;str[i];i++)
               counter+=arr[str[i]-65];
        return counter;
}

Enormous Input Test - Solution


Problem Statement :
The purpose of this problem is to verify whether the method you are using to read input data is sufficiently fast to handle problems branded with the enormous Input/Output warning. You are expected to be able to process at least 2.5MB of input data per second at runtime.

Input

The input begins with two positive integers n k (n, k<=107). The next n lines of input contain one positive integer ti, not greater than 109, each.

Output

Write a single integer to output, denoting how many integers ti are divisible by k.

Example

Input:
7 3
1
51
966369
7
9
999996
11
 
Output:
4

Solution
#include<stdio.h>
 
int main()
{
        long i,n,k,counter=0,number;
        scanf("%d%d",&n,&k);
        for(i=0;i<n;i++)
        {
               scanf("%d",&number);
               if(number%k==0)
                       counter++;
        }
        printf("%d",counter);
        return 0;
        
}

ATM - Solution


Problem Statement:
Pooja would like to withdraw X $US from an ATM. The cash machine will only accept the transaction if X is a multiple of 5, and Pooja's account balance has enough cash to perform the withdrawal transaction (including bank charges). For each successful withdrawal the bank charges 0.50 $US.
Calculate Pooja's account balance after an attempted transaction.

Input

Positive integer 0 < X <= 2000 - the amount of cash which Pooja wishes to withdraw.
Nonnegative number 0<= Y <= 2000 with two digits of precision - Pooja's initial account balance.

Output

Output the account balance after the attempted transaction, given as a number with two digits of precision. If there is not enough money in the account to complete the transaction, output the current bank balance.

Example - Successful Transaction

Input:
30 120.00
 
Output:
89.50

Example - Incorrect Withdrawal Amount (not multiple of 5)

Input:
42 120.00
 
Output:
120.00

Example - Insufficient Funds

Input:
300 120.00
 
Output:
120.00


Solution
#include<stdio.h>
 
int main()
{
               int withdraw;
               float tot_bal;
               float new_bal;
               scanf("%d",&withdraw);
               scanf("%f",&tot_bal);
               if(withdraw>=tot_bal-0.5 || withdraw % 5!=0)
               {
                       printf("%.2f",tot_bal);
               }
               else
               {
                               new_bal=tot_bal-withdraw-0.5;
                               printf("%.2f",new_bal);
               }
               return 0;
}

Turbo Sort - Solution


Problem Statement:
Given the list of numbers, you are to sort them in non decreasing order.

Input

t – the number of numbers in list, then t lines follow [t <= 10^6].

Each line contains one integer: N [0 <= N <= 10^6]

Output

Output given numbers in non decreasing order.

Example

Input:
5
5
3
6
7
1
Output:
1
3
5
6
7
 
Solution:
 
 
#include<stdio.h>
 
int main()
{
        int i,num,arr[1000001]={0},n;
        scanf("%d",&num);
        for(i=0;i<num;i++)
        {
               scanf("%d",&n);
               arr[n]++;
        }
        for(i=0;i<1000001;i++)
               if(arr[i])
                       while(arr[i]--)
                               printf("%d\n",i);
        return 0;
}
 

Factorial - Solution


The most important part of a GSM network is so called
Base Transceiver Station (BTS). These transceivers form the
areas called cells (this term gave the name to the cellular phone)
and every phone connects to the BTS with the strongest signal (in
a little simplified view). Of course, BTSes need some attention and
technicians need to check their function periodically.


The technicians faced a very interesting problem recently. Given a set of
BTSes to visit, they needed to find the shortest path to visit all of the
given points and return back to the central company building. Programmers
have spent several months studying this problem but with no results. They
were unable to find the solution fast enough. After a long time, one of the
programmers found this problem in a conference article. Unfortunately, he
found that the problem is so called "Traveling Salesman Problem" and it is
very hard to solve. If we have N BTSes to be visited, we can visit them in
any order, giving us N! possibilities to examine. The function expressing
that number is called factorial and can be computed as a product
1.2.3.4....N. The number is very high even for a relatively small N.


The programmers understood they had no chance to solve the problem. But
because they have already received the research grant from the government,
they needed to continue with their studies and produce at least some
results. So they started to study behavior of the factorial function.


For example, they defined the function Z. For any positive integer N,
Z(N) is the number of zeros at the end of the decimal form of number
N!. They noticed that this function never decreases. If we have two numbers
N1<N2, then
Z(N1) <= Z(N2). It is because we can never "lose" any
trailing zero by multiplying by any positive number. We can only get new
and new zeros. The function Z is very interesting, so we need a computer
program that can determine its value efficiently.

Input


There is a single positive integer T on the first line of input (equal to about 100000). It stands
for the number of numbers to follow. Then there are T lines, each containing
exactly one positive integer number N,
1 <= N <= 1000000000.

Output


For every number N, output a single line containing the single non-negative
integer Z(N).

Example

Sample Input:
6
3
60
100
1024
23456
8735373
Sample Output:
0
14
24
253
5861
2183837


Solution

#include<stdio.h>   
#include<math.h>
 
int fun(int);
int main()
{
        int t,i,n;
        scanf("%d",&t);
        for(i=0;i<t;i++)
        {       
               scanf("%d",&n);        
                printf("%d\n",fun(n));
        }
        return 0;
}
   
   
int fun(int n)   
{       
        int i,counter=0;       
        for(i=1;pow(5,i)<=n;i++)
        {
                counter+=n/pow(5,i);   
        }
        
        return counter;
}

Life, the Universe, and Everything - Solution

Problem Statement:
Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits.

Example

 
Input:
1
2
88
42
99
 
Output:
1
2
88

Solution:
#include<stdio.h>
#include<stdlib.h>
int main()
{
        int i,*arr,j;
        arr=NULL;
        for(i=0;;i++)
        {
               arr=(int*)realloc(arr,sizeof(int)*(i+1));
               scanf("%d",&arr[i]);
               if(arr[i]==42)
               {
                       break;
               }
        }
        for(j=0;j<i;j++)
               printf("%d\n",arr[j]);
        
}

PROJECT EULER SOLUTION # 60


Solution to problem number 60 of Project Euler.
Question # 60
The primes 3, 7, 109, and 673, are quite remarkable. By taking any two primes and concatenating them in any order the result will always be prime. For example, taking 7 and 109, both 7109 and 1097 are prime. The sum of these four primes, 792, represents the lowest sum for a set of four primes with this property.
Find the lowest sum for a set of five primes for which any two primes concatenate to produce another prime.

Solution # 60
/**********************************************************************/
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

#define max 1000000

int arr[max]={0};

void set_arr();
int is_prime(long int);
int is_conPrime(long int, long int);

int main()
{
      long int i,sum=0,a,b,c,d,e,min=2147483647;
      set_arr();
      for(a=3;a<10000;a+=2)
            if(arr[a])
                  for(b=3;b<10000;b+=2)
                        if(arr[b] && is_conPrime(a,b))
                              for(c=3;c<10000;c+=2)
                                    if(arr[c] && is_conPrime(a,c) && is_conPrime(b,c))
                                          for(d=3;d<10000;d+=2)
                                                if(arr[d] && is_conPrime(a,d) && is_conPrime(b,d) && is_conPrime(c,d))
                                                      for(e=3;e<10000;e+=2)
                                                            if(arr[e] && is_conPrime(a,e) && is_conPrime(b,e) && is_conPrime(c,e) && is_conPrime(d,e))
                                                            {
                                                                  printf("%ld %ld %ld %ld %ld\nsum = %ld",a,b,c,d,e,(a+b+c+d+e));
                                                                  exit(1);
                                                            }


      return 0;
}

void set_arr()
{
      int i;
      for(i=2;i<max;i++)
            if(is_prime(i))
                  arr[i]=1;
}

int is_prime(long int n)
{
      long int i;
      if(n==1)
            return 0;
      if(n==2)
            return 1;
      if(n%2==0)
            return 0;
      for(i=3;i*i<=n;i+=2)
            if(n%i==0)
                  return 0;
      return 1;
}

int count_digits(long int n)
{
      int counter=0;
      while(n)
      {
            counter++;
            n/=10;
      }
      return counter;
}

int is_conPrime(long int a,long int b)
{
      long int num1,num2;
      num1=a+b*(long)pow(10,count_digits(a));
      num2=b+a*(long)pow(10,count_digits(b));
      if(is_prime(num1) && is_prime(num2))
            return 1;
      return 0;
}
/**********************************************************************/