周结

这周没有vj题目就写写这个周做的cf 的题目吧,cf到现在打了十多场了,但是每次结果都是惨不忍睹,有种答案跟我咫尺天涯的无奈感,总结一下还是做题做的太少了,以后应该多动动脑子少看看题解,活跃一下思维了

K-th Not Divisible by n

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given two positive integers nn and kk. Print the kk-th positive integer that is not divisible by nn.

For example, if n=3n=3, and k=7k=7, then all numbers that are not divisible by 33 are: 1,2,4,5,7,8,10,11,13…1,2,4,5,7,8,10,11,13…. The 77-th number among them is 1010.

Input

The first line contains an integer tt (1≤t≤10001≤t≤1000) — the number of test cases in the input. Next, tt test cases are given, one per line.

Each test case is two positive integers nn (2≤n≤1092≤n≤109) and kk (1≤k≤1091≤k≤109).

Output

For each test case print the kk-th positive integer that is not divisible by nn.

Example

input

Copy

6
3 7
4 12
2 1000000000
7 97
1000000000 1000000000
2 1

output

Copy

10
15
1999999999
113
1000000001
1

这个题目我最开始做的时候就卡在了怎么找出缺几个数的情况,因为感觉会有很多中情况,下面介绍一种分组的方法 

首先从1开始的第k个数本来是k,但因为中间的某一些数因为是n的倍数不能取,所以答案为k+某个数。我们要求的就是这个数。
以第二组数据为例:
4 12
1,2,3@5,6,7@9,10,11@13,14,15
第12个数是15。前12个数有3个@,所以是12+3=15。所以这个数即为@的数量。也就是分的组数

但是@的数量不好求,我们可以先求出组数:
因为每组有(n-1)个数,所以组数为k/(n-1)上取整,而分割线的数量即为组数-1,因此答案即为(k+n-1)/(n-1)-1。这个数可以简化为(k-1)/(n-1)。

 

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#define LL long long
using namespace std;
int const N=1e5+5;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		cout<<k+(k-1)/(n-1)<<endl; 
	}
    return 0;
}

Same Parity Summands

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given two positive integers nn (1≤n≤1091≤n≤109) and kk (1≤k≤1001≤k≤100). Represent the number nn as the sum of kk positive integers of the same parity (have the same remainder when divided by 22).

In other words, find a1,a2,…,aka1,a2,…,ak such that all ai>0ai>0, n=a1+a2+…+akn=a1+a2+…+ak and either all aiai are even or all aiai are odd at the same time.

If such a representation does not exist, then report it.

Input

The first line contains an integer tt (1≤t≤10001≤t≤1000) — the number of test cases in the input. Next, tt test cases are given, one per line.

Each test case is two positive integers nn (1≤n≤1091≤n≤109) and kk (1≤k≤1001≤k≤100).

Output

For each test case print:

  • YES and the required values aiai, if the answer exists (if there are several answers, print any of them);
  • NO if the answer does not exist.

The letters in the words YES and NO can be printed in any case.

Example

input

Copy

8
10 3
100 4
8 7
97 2
8 8
3 10
5 3
1000000000 9

output

Copy

YES
4 2 4
YES
55 5 5 35
NO
NO
YES
1 1 1 1 1 1 1 1
NO
YES
3 1 1
YES
111111110 111111110 111111110 111111110 111111110 111111110 111111110 111111110 111111120

昨晚把情况想多了就一直做不出来 ,最后的时候想到了今天看的题解的这种方式,知道可以压缩但是太急了又不知道怎么去实现,最后只能看着红红的答案,哎,做题不能急,而且自己还差的远

 看看这个题目把,就是把所有情况压缩成两种情况,要么我用奇数,要么我用偶数,如果都用奇数我要看看最后剩的数是不是奇数,并且最后剩的是不是大于零,偶数的话则相反,这个题目就迎刃而解了

#include <iostream>
using namespace std;
int main() {
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		int n1 = n - (k - 1);
		//把k-1个1去掉看是不是奇数 
		if (n1 > 0 && n1 % 2 == 1) {
			cout << "YES" << endl;
			for (int i = 0; i < k - 1; i ++ ) cout << "1 ";
			cout << n1 << endl;
			continue;
		}
		int n2 = n - 2 * (k - 1);
		//把k-1个2去掉看是不是偶数 
		if (n2 > 0 && n2 % 2 == 0) {
			cout << "YES" << endl;
			for (int i = 0; i < k - 1; i ++ ) cout << "2 ";
			cout << n2 << endl;
			continue;
		}
		//上述情况都不是则无解 
		cout << "NO" << endl;
	}
}

 

Card Constructions

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

A card pyramid of height 11 is constructed by resting two cards against each other. For h>1h>1, a card pyramid of height hh is constructed by placing a card pyramid of height h−1h−1 onto a base. A base consists of hh pyramids of height 11, and h−1h−1 cards on top. For example, card pyramids of heights 11, 22, and 33 look as follows:

Card Constructions

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

A card pyramid of height 11 is constructed by resting two cards against each other. For h>1h>1, a card pyramid of height hh is constructed by placing a card pyramid of height h−1h−1 onto a base. A base consists of hh pyramids of height 11, and h−1h−1 cards on top. For example, card pyramids of heights 11, 22, and 33 look as follows:

You start with nn cards and build the tallest pyramid that you can. If there are some cards remaining, you build the tallest pyramid possible with the remaining cards. You repeat this process until it is impossible to build another pyramid. In the end, how many pyramids will you have constructed?

Input

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤10001≤t≤1000) — the number of test cases. Next tt lines contain descriptions of test cases.

Each test case contains a single integer nn (1≤n≤1091≤n≤109) — the number of cards.

It is guaranteed that the sum of nn over all test cases does not exceed 109109.

Output

For each test case output a single integer — the number of pyramids you will have constructed in the end.

Example

input

Copy

5
3
14
15
24
1

output

Copy

1
2
1
3
0

Note

In the first test, you construct a pyramid of height 11 with 22 cards. There is 11 card remaining, which is not enough to build a pyramid.

In the second test, you build two pyramids, each of height 22, with no cards remaining.

In the third test, you build one pyramid of height 33, with no cards remaining.

In the fourth test, you build one pyramid of height 33 with 99 cards remaining. Then you build a pyramid of height 22 with 22 cards remaining. Then you build a final pyramid of height 11 with no cards remaining.

In the fifth test, one card is not enough to build any pyramids.

 

You start with nn cards and build the tallest pyramid that you can. If there are some cards remaining, you build the tallest pyramid possible with the remaining cards. You repeat this process until it is impossible to build another pyramid. In the end, how many pyramids will you have constructed?

Input

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤10001≤t≤1000) — the number of test cases. Next tt lines contain descriptions of test cases.

Each test case contains a single integer nn (1≤n≤1091≤n≤109) — the number of cards.

It is guaranteed that the sum of nn over all test cases does not exceed 109109.

Output

For each test case output a single integer — the number of pyramids you will have constructed in the end.

Example

input

Copy

5
3
14
15
24
1

output

Copy

1
2
1
3
0

Note

In the first test, you construct a pyramid of height 11 with 22 cards. There is 11 card remaining, which is not enough to build a pyramid.

In the second test, you build two pyramids, each of height 22, with no cards remaining.

In the third test, you build one pyramid of height 33, with no cards remaining.

In the fourth test, you build one pyramid of height 33 with 99 cards remaining. Then you build a pyramid of height 22 with 22 cards remaining. Then you build a final pyramid of height 11 with no cards remaining.

In the fifth test, one card is not enough to build any pyramids.

要说这个题目其实就更有意思了,思路套路都对但是做的时候就一直卡runtime和timelimited但是其实赛后我重新做将数据运算提到括号外就直接暴力刚好也能过,易求出小于1e9的卡片数所能拼出的最高层数是25820,那么让n与25820层~1层依次比较,如果n大于a[i],那么n-=a[i],同时ans++,就能得出答案。并不需要二分求解

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N=3e5;
typedef long long ll;
int a[N];
int main()
{
	int t;
	cin>>t;
	a[1]=2;
	for(int i=2;i;i++) 
	{
		a[i]=a[i-1]+3*i-1;
		if(a[i]>1e9) break;
	}
	while(t--)
	{
		int num;
		cin>>num;
		int ans=0;
		for(int i=25820;i>=1;i--)
		{
			while(num>=a[i])
			{
				num-=a[i];
				ans++;
			}
		}
		cout<<ans<<endl;	
	}
	
	return 0;
}

这三个题目都是我这个周打比赛我觉得自己能够ac但是最后没有ac的题目,问题出在了哪里显而易见,现在仔细看看总结这三道题目并不难,而且在比赛的过程中我做的离答案已经很接近了,但是做不出来不能抱怨什么时运不齐,运气不好,一次可以说是运气但是次次都是这样呢???很明显就是水平不足,但也不是水平太差,希望自己可以更多的总结打破这个明明可以却根本不行的瓶颈。加油吧 


 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值