Codeforces Round #451 (Div. 2)

A. Rounding
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya has a non-negative integer n. He wants to round it to nearest integer, which ends up with 0. If n already ends up with 0, Vasya considers it already rounded.

For example, if n = 4722 answer is 4720. If n = 5 Vasya can round it to 0 or to 10. Both ways are correct.

For given n find out to which integer will Vasya round it.

Input

The first line contains single integer n (0 ≤ n ≤ 109) — number that Vasya has.

Output

Print result of rounding n. Pay attention that in some cases answer isn't unique. In that case print any correct answer.

Examples
input
5
output
0
input
113
output
110
input
1000000000
output
1000000000
input
5432359
output
5432360
Note

In the first example n = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
#define MOD 1000000007
#define N 1000005
int main()
{
    ll n;
    while(cin>>n)
    {
        int temp=0;
        for(ll i=n;;i++)
        {
            temp++;
            if(i%10==0)
            {
                break;
            }
        }
        if(temp>10-temp)
            cout<<n-(10-temp)-1<<endl;
        else cout<<n+temp-1<<endl;
    }
    return 0;
}

B. Proper Nutrition
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya has n burles. One bottle of Ber-Cola costs a burles and one Bars bar costs b burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.

Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly n burles.

In other words, you should find two non-negative integers x and y such that Vasya can buy x bottles of Ber-Cola and y Bars bars and x·a + y·b = n or tell that it's impossible.

Input

First line contains single integer n (1 ≤ n ≤ 10 000 000) — amount of money, that Vasya has.

Second line contains single integer a (1 ≤ a ≤ 10 000 000) — cost of one bottle of Ber-Cola.

Third line contains single integer b (1 ≤ b ≤ 10 000 000) — cost of one Bars bar.

Output

If Vasya can't buy Bars and Ber-Cola in such a way to spend exactly n burles print «NO» (without quotes).

Otherwise in first line print «YES» (without quotes). In second line print two non-negative integers x and y — number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly n burles, i.e. x·a + y·b = n. If there are multiple answers print any of them.

Any of numbers x and y can be equal 0.

Examples
input
7
2
3
output
YES
2 1
input
100
25
10
output
YES
0 10
input
15
4
8
output
NO
input
9960594
2551
2557
output
YES
1951 1949
Note

In first example Vasya can buy two bottles of Ber-Cola and one Bars bar. He will spend exactly 2·2 + 1·3 = 7 burles.

In second example Vasya can spend exactly n burles multiple ways:

  • buy two bottles of Ber-Cola and five Bars bars;
  • buy four bottles of Ber-Cola and don't buy Bars bars;
  • don't buy Ber-Cola and buy 10 Bars bars.

In third example it's impossible to but Ber-Cola and Bars bars in order to spend exactly n burles.

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
#define MOD 1000000007
#define N 1000005
#define INF 0x3f3f3f3f3f3f
ll a,b,c;
ll exgcd(ll a,ll b,ll &x,ll &y)
{
    if(!b)
    {
        x=1;
        y=0;
        return a;
    }
    ll d=exgcd(b,a%b,y,x);
    y-=a/b*x;
    return d;
}
int main()
{
    ll a,b,c;
    ll t;
    while(cin>>c>>a>>b)
    {
        /*ll x,y;
        ll d=exgcd(a,b,x,y);
        if(c%d!=0)
            cout<<"NO"<<endl;
        else
        {
            cout<<"YES"<<endl;
            ll ansx=c*x/d;
            ll ansy=c*y/d;
            cout<<ansx<<" "<<ansy<<endl;*/
            int flag=0,temp;
            for(int i=0;i<=c/a;i++)
            {
                if((c-a*i)%b==0)
                {
                    temp=i;
                    flag=1;
                    break;
                }

            }
            if(flag==0)
                cout<<"NO"<<endl;
            else
            {

                cout<<"YES"<<endl;
                cout<<temp<<" "<<(c-temp*a)/b<<endl;;
            }
        }
    return 0;
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章