Algorithm of 10533 - Digit Primes

Problem Description Link

Algorithm:

This is a simple prime related problem
if a number is a prime then check that if sum of prime digit also prime then this digit is called digit prime
For example the prime number 41 is a digit prime because 4+1=5 and 5 is a prime number. 17 is not a digit prime because 1+7 = 8, and 8 is not a prime number.
But to solve this problem if you follow ittarative way then you may got TLE.
so you must generate prime and digit-prime before goe input.
and follow this technique.
1.pre calculate number of digit primes from 1 to 1000000
2. when you get t1 & t2 , number of digit primes t2 subtract number of digit primes t1-1
3. if t1 = 10, t2 = 100 . Number of digit primes at 10 is 4 and number of digit primes at 100 is 14
so dprime[100] - dprime[10-1] = 14 - 4 = 10
4. print the difference.

image

Solution of 10533 - Digit Primes

Problem Description
source:https://uva.onlinejudge.org/external/105/10533.html

A prime number is a positive number, which is divisible by exactly two different integers. A digit prime is a prime number whose sum of digits is also prime. For example the prime number 41 is a digit prime because 4 + 1 = 5 and 5 is a prime number. 17 is not a digit prime because 1 + 7 = 8, and 8 is not a prime number. In this problem your job is to find out the number of digit primes within a certain range less than 1000000. 

Input 

First line of the input file contains a single integer N (0 < N ≤ 500000) that indicates the total number of inputs. Each of the next N lines contains two integers t1 and t2 (0 < t1 ≤ t2 < 1000000). 

Output 

image

Algorithm of 406 - Prime Cuts

Problem Description Link
Algorithm:

This is a prime related problem . In this problem you need to   generate the  prime number from 1 to N.
Where 1 also a prime number in this problem .
After generate the all prime number from 1 to N count the prime numbers check.
 I f prime numbers are even then print the center (c*2) primes  .
I f prime numbers are odd then print the center (c*2-1) primes  .
If center (c*2) for even or (c*2-1) for odd excite the list of all prime numbers then print all prime from 1 to N
For example.
image

Solution of 406 - Prime Cuts

Problem Description
source:https://uva.onlinejudge.org/external/4/406.html

A prime number is a counting number (1, 2, 3, . . .) that is evenly divisible only by 1 and itself. In this problem you are to write a program that will cut some number of prime numbers from the list of prime numbers between (and including) 1 and N. Your program will read in a number N; determine the list of prime numbers between 1 and N; and print the 2C prime numbers from the center of the list if there are an even number of prime numbers or 2C − 1 prime numbers from the center of the list if there are an odd number of prime numbers in the list.

Input 

Each input set will be on a line by itself and will consist of 2 numbers. The first number (1 ≤ N ≤ 1000) is the maximum number in the complete list of prime numbers between 1 and N. The second number (1 ≤ C ≤ N) defines the 2C prime numbers to be printed from the center of the list if the length of the list is even; or the 2C − 1 numbers to be printed from the center of the list if the length of the list is odd.

image

Solution of 12342 - Tax Calculator

Problem Description
source:https://uva.onlinejudge.org/external/123/12342.html

People of a certain country have a little interest in paying tax. This is not the case that they do not love the country or they do not want to obey the law, but the problem is the complex calculations for payable tax. Most of the people do not understand the rule and some lawyers take high charges to help(?) them. So, most of the people just avoid paying tax. Realizing this, the Government decided to automate the taxpaying system and appointed you to program a tax calculator that takes a persons yearly income as input and calculate the payable tax for him. Here is the rule for calculate payable tax for an individual:
1. The first 180,000/- of income is tax free.
2. Next 300,000/- will have 10% tax.
3. Next 400,000/- will have 15% tax.
4. Next 300,000/- will have 20% tax.
5. The rest will have 25% tax.

Solution of 12068 - Harmonic Mean

Problem Description
source:https://uva.onlinejudge.org/external/120/12068.html

Input 

The first line of the input file contains an integer S (0 < S < 501), which indicates how many sets of inputs are there. Each of the next S lines contains one set of input. The description of each set is given below: Each set starts with an integer N (0 < N < 9), which indicates how many numbers are there in this set. This number is followed by N integers a1, a2, a3 . . . aN−1, aN (0 < ai < 101). 

Algorithm of 12043 - Dvisor

Problem Description Link
Algorithm:
In this problem if you use more loop in main program to determine the number of divisor and sum of divisor may be you get time limit exit .
so before test case you must generate two array for divisor and sum_of_divisor and and finally use a loop l
i=a to b and check that if any value i mod k is zero then add div+=divisor[i] and sum+=sum_of_divisor[i];
To generate divisor[] and sum_of_divisor[] you can use siv method
that method is bellow :
at first you must set each element 1 in divisor[] and sum_of_divisor[] after then
image

Solution of 12043 - Dvisor

Problem Description
source:https://uva.onlinejudge.org/external/120/12043.html


Let us define the functions d(n) and σ(n) as 
d(n) = number of divisors of n 
σ(n) = summation of divisors of n 

Here divisors of n include both 1 and n. For example divisors of 6 are 1, 2, 3 and 6. So d(6) = 4 and σ(n) = 12. 
Now let us define two more function g(a, b, k) and h(a, b, k) as 

g(a, b, k) = ∑ i d(i) 
h(a, b, k) = ∑ i σ(i) 

Where a ≤ i ≤ b and i is divisible by k. 

image

Solution of 12015 - Google is Feeling Lucky

Problem Description
source:https://uva.onlinejudge.org/external/120/12015.html

Google is one of the most famous Internet search engines which hosts and develops a number of Internetbased services and products. On its search engine website, an interesting button ‘I’m feeling lucky’ attracts our eyes. This feature could allow the user skip the search result page and goes directly to the first ranked page. Amazing! It saves a lot of time. The question is, when one types some keywords and presses ‘I’m feeling lucky’ button, which web page will appear? Google does a lot and comes up with excellent approaches to deal with it. In this simplified problem, let us just consider that Google assigns every web page an integer-valued relevance. The most related page will be chosen. If there is a tie, all the pages with the highest relevance are possible to be chosen. Your task is simple, given 10 web pages and their relevance. Just pick out all the possible candidates which will be served to the user when ‘I’m feeling lucky’.

Input 

The input contains multiple test cases. The number of test cases T is in the first line of the input file. For each test case, there are 10 lines, describing the web page and the relevance. Each line contains a character string without any blank characters denoting the URL of this web page and an integer Vi denoting the relevance of this web page. The length of the URL is between 1 and 100 inclusively. (1 ≤ Vi ≤ 100) 

Output 

For each test case, output several lines which are the URLs of the web pages which are possible to be chosen. The order of the URLs is the same as the input. Please look at the sample output for further information of output format.

Sample Input


www.youtube.com 1 
www.google.com 2 
www.google.com.hk 3 
www.alibaba.com 10 
www.taobao.com 5 
www.bad.com 10 
www.good.com 7 
www.fudan.edu.cn 8 
www.university.edu.cn 9 
acm.university.edu.cn 10 
www.youtube.com 1 
www.google.com 2 
www.google.com.hk 3 
www.alibaba.com 11 
www.taobao.com 5 
www.bad.com 10 
www.good.com 7 
www.fudan.edu.cn 8 
acm.university.edu.cn 9 
acm.university.edu.cn 10 

Sample Output 

Case #1: www.alibaba.com www.bad.com acm.university.edu.cn 
Case #2: www.alibaba.com

Solution
#include<stdio.h>

int main()
{
    int t, i, j, k, max, value[15];
    char url[12][105];
    while(scanf("%d",&t)==1)
    {
        for(i=1;i<=t;i++)
        {
            max=0;
            for(j=1;j<=10;j++)
            {
                scanf("%s%d",&url[j], &value[j]);
                if(value[j]>max)
                    max=value[j];
            }
            printf("Case #%d:\n",i);
            for(k=1;k<=10;k++)
            {
                if(max==value[k])
                    printf("%s\n",url[k]);
            }
        }
    }
    return 0;
}
image

Solution of 11995 - I Can Guess the Data Structure!

Problem Description
source:https://uva.onlinejudge.org/external/119/p11995.pdf

There is a bag-like data structure, supporting two operations: 

1 x      Throw an element x into the bag. 
2         Take out an element from the bag. 

Given a sequence of operations with return values, you’re going to guess the data structure. It is a stack (Last-In, First-Out), a queue (First-In, First-Out), a priority-queue (Always take out larger elements first) or something else that you can hardly imagine!