Codeforces Round #739 (Div. 3)

A. Dislike of Threes

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Polycarp doesn't like integers that are divisible by 33 or end with the digit 33 in their decimal representation. Integers that meet both conditions are disliked by Polycarp, too.

Polycarp starts to write out the positive (greater than 00) integers which he likes: 1,2,4,5,7,8,10,11,14,16,…1,2,4,5,7,8,10,11,14,16,…. Output the kk-th element of this sequence (the elements are numbered from 11).

Input

The first line contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases. Then tt test cases follow.

Each test case consists of one line containing one integer kk (1≤k≤10001≤k≤1000).

Output

For each test case, output in a separate line one integer xx — the kk-th element of the sequence that was written out by Polycarp.

Example

input

10
1
2
3
4
5
6
7
8
9
1000

output

1
2
4
5
7
8
10
11
14
1666

数据不大,1000,暴力枚举即可。

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int k=0;
        for(int i=1;i<2*n;i++)
        {
            if(i%10!=3&&i%3!=0)
            {
                k++;
            }
            if(k==n)
            {
                cout<<i<<endl;
                break;
            }
        }
    }
}

B. Who's Opposite?

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Some number of people (this number is even) have stood in a circle. The people stand in the circle evenly. They are numbered clockwise starting from a person with the number 11. Each person is looking through the circle's center at the opposite person.

A sample of a circle of 66 persons. The orange arrows indicate who is looking at whom.

 

You don't know the exact number of people standing in the circle (but this number is even, no doubt). It is known that the person with the number aa is looking at the person with the number bb (and vice versa, of course). What is the number associated with a person being looked at by the person with the number cc? If, for the specified aa, bb, and cc, no such circle exists, output -1.

Input

The first line contains one integer tt (1≤t≤1041≤t≤104) — the number of test cases. Then tt test cases follow.

Each test case consists of one line containing three distinct integers aa, bb, cc (1≤a,b,c≤1081≤a,b,c≤108).

Output

For each test case output in a separate line a single integer dd — the number of the person being looked at by the person with the number cc in a circle such that the person with the number aa is looking at the person with the number bb. If there are multiple solutions, print any of them. Output −1−1 if there's no circle meeting the given conditions.

Example

input

Copy

7
6 2 4
2 3 1
2 4 10
5 3 4
1 3 2
2 5 4
4 3 2

output

Copy

8
-1
-1
-1
4
1
-1

Note

In the first test case, there's a desired circle of 88 people. The person with the number 66 will look at the person with the number 22 and the person with the number 88 will look at the person with the number 44.

In the second test case, there's no circle meeting the conditions. If the person with the number 22 is looking at the person with the number 33, the circle consists of 22 people because these persons are neighbors. But, in this case, they must have the numbers 11 and 22, but it doesn't meet the problem's conditions.

In the third test case, the only circle with the persons with the numbers 22 and 44 looking at each other consists of 44 people. Therefore, the person with the number 1010 doesn't occur in the circle.

面对面数字的绝对值的两倍就是所有数的上限,只要a,b,c

不超过这个限制就会有答案,

 只要和c相距ab的绝对值的数在范围内的就是答案了

 

#include <iostream>
#include <cstring>
#include<cmath>
#include <algorithm>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int a,b,c;
        cin>>a>>b>>c;
        int d=abs(a-b)*2;
        if(c>d||a>d||b>d)
        {
            cout<<-1<<endl;
        }
        else
        {
            int f=d/2;
            if((c-f<=d&&c-f>=1))
            {
                cout<<abs(c-f)<<endl;
            }
            else
            if(c+f<=d)
            {
                cout<<c+f<<endl;
            }
        }
    }
}

C. Infinity Table

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Polycarp has found a table having an infinite number of rows and columns. The rows are numbered from 11, starting from the topmost one. The columns are numbered from 11, starting from the leftmost one.

Initially, the table hasn't been filled and Polycarp wants to fix it. He writes integers from 11 and so on to the table as follows.

The figure shows the placement of the numbers from 11 to 1010. The following actions are denoted by the arrows.

The leftmost topmost cell of the table is filled with the number 11. Then he writes in the table all positive integers beginning from 22 sequentially using the following algorithm.

First, Polycarp selects the leftmost non-filled cell in the first row and fills it. Then, while the left neighbor of the last filled cell is filled, he goes down and fills the next cell. So he goes down until the last filled cell has a non-filled neighbor to the left (look at the vertical arrow going down in the figure above).

After that, he fills the cells from the right to the left until he stops at the first column (look at the horizontal row in the figure above). Then Polycarp selects the leftmost non-filled cell in the first row, goes down, and so on.

A friend of Polycarp has a favorite number kk. He wants to know which cell will contain the number. Help him to find the indices of the row and the column, such that the intersection of the row and the column is the cell containing the number kk.

Input

The first line contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases. Then tt test cases follow.

Each test case consists of one line containing one integer kk (1≤k≤1091≤k≤109) which location must be found.

Output

For each test case, output in a separate line two integers rr and cc (r,c≥1r,c≥1) separated by spaces — the indices of the row and the column containing the cell filled by the number kk, respectively.

Example

input

Copy

7
11
14
5
4
1
2
1000000000

output

Copy

2 4
4 3
1 3
2 1
1 1
1 2
31623 14130

题意

就是环形排数字

1  2  5  10

4  3  6  11

9  8  7  12

16 15 14 13

 找规律发现,

根号n就是限制正方体大小的限制

#include <iostream>
#include <cstring>
#include<cmath>
#include <algorithm>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int k=sqrt(n);
        int f=n-k*k;
        if(f==0)
        {
            cout<<k<<" "<<1<<endl;
        }
        else if(f<=k+1)
        {
            cout<<f<<" "<<k+1<<endl;
        }
        else 
        {
            cout<<k+1<<" "<<2*k+2-f<<endl;
        }
    }
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值