Codeforces Beta Round #69 (Div. 2 Only)——A,B,D

来源:互联网 发布:遍历所有子节点 js 编辑:程序博客网 时间:2024/05/22 16:55
A. Panoramix's Prediction
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 273 are prime, and 16,4 are not.

The next prime number after x is the smallest prime number greater than x. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2.

One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.

Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly x Roman soldiers, where x is a prime number, and next day they beat exactly y Roman soldiers, where y is the next prime number after x, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.

Yesterday the Gauls beat n Roman soldiers and it turned out that the number n was prime! Today their victims were a troop of mRomans (m > n). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?

Input

The first and only input line contains two positive integers — n and m (2 ≤ n < m ≤ 50). It is guaranteed that n is prime.

Pretests contain all the cases with restrictions 2 ≤ n < m ≤ 4.

Output

Print YES, if m is the next prime number after n, or NO otherwise.

#include <iostream>#include <cstdio>using namespace std;bool judge(int x){    bool flag=true;    for(int i=2;i*i<=x;i++)        if(x%i==0) flag=false;    return flag;}int main(){    int a,b,i;    cin>>a>>b;    for(i=a+1;;i++)        if(judge(i)) break;    if(i==b) cout<<"YES"<<endl;    else cout<<"NO"<<endl;    return 0;}

B. Depression
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!

There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle...

Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock.

Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll.

Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00.

You can only rotate the hands forward, that is, as is shown in the picture:

As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction.

Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.

Input

The only line of input contains current time according to the digital clock, formatted as HH:MM (00 ≤ HH ≤ 2300 ≤ MM ≤ 59). The mantel clock initially shows 12:00.

Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.

Output

Print two numbers x and y — the angles of turning the hour and minute hands, respectively (0 ≤ x, y < 360). The absolute or relative error in the answer should not exceed 10 - 9.

#include <iostream>#include <cstdio>using namespace std;int main(){    int a,b;    scanf("%d:%d",&a,&b);    int y=b*6;    if(a>=12) a-=12;    double x=(a*60+b*1.0)/2;    if(x==(int)x)        printf("%.0lf %d",x,y);    else        printf("%.1lf %d",x,y);    cout<<endl;    return 0;}

D. Falling Anvils
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all.

Anvils come in different sizes and shapes. Quite often they get the hero stuck deep in the ground. But have you ever thought who throws anvils from the sky? From what height? We are sure that such questions have never troubled you!

It turns out that throwing an anvil properly is not an easy task at all. Let's describe one of the most popular anvil throwing models.

Let the height p of the potential victim vary in the range [0;a] and the direction of the wind q vary in the range [ - b;b]p and q could be any real (floating) numbers. Then we can assume that the anvil will fit the toon's head perfectly only if the following equation has at least one real root:

Determine the probability with which an aim can be successfully hit by an anvil.

You can assume that the p and q coefficients are chosen equiprobably and independently in their ranges.

Input

The first line contains integer t (1 ≤ t ≤ 10000) — amount of testcases.

Each of the following t lines contain two space-separated integers a and b (0 ≤ a, b ≤ 106).

Pretests contain all the tests with 0 < a < 10, 0 ≤ b < 10.

Output

Print t lines — the probability of a successful anvil hit for each testcase. The absolute or relative error of the answer should not exceed10 - 6.

#include <iostream>#include <cstdio>using namespace std;int main(){    int t;    cin>>t;    while(t--)    {        double a,b;        cin>>a>>b;        if(b==0)        {            printf("1\n");            continue;        }        double ans=0.5;        //画图求解即可,b为x轴,注意a/4与b的关系即可        if(a>b*4) ans+=0.5-b/a;        else ans+=a/16/b;        printf("%.10lf\n",ans);    }    return 0;}


原创粉丝点击