codeforces round 641div2

codeforces round 641div2

好久没写博客了

A. Orac and Factors
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Orac is studying number theory, and he is interested in the properties of divisors.

For two positive integers 𝑎 and 𝑏, 𝑎 is a divisor of 𝑏 if and only if there exists an integer 𝑐, such that 𝑎⋅𝑐=𝑏.

For 𝑛≥2, we will denote as 𝑓(𝑛) the smallest positive divisor of 𝑛, except 1.

For example, 𝑓(7)=7,𝑓(10)=2,𝑓(35)=5.

For the fixed integer 𝑛, Orac decided to add 𝑓(𝑛) to 𝑛.

For example, if he had an integer 𝑛=5, the new value of 𝑛 will be equal to 10. And if he had an integer 𝑛=6, 𝑛 will be changed to 8.

Orac loved it so much, so he decided to repeat this operation several times.

Now, for two positive integers 𝑛 and 𝑘, Orac asked you to add 𝑓(𝑛) to 𝑛 exactly 𝑘 times (note that 𝑛 will change after each operation, so 𝑓(𝑛) may change too) and tell him the final value of 𝑛.

For example, if Orac gives you 𝑛=5 and 𝑘=2, at first you should add 𝑓(5)=5 to 𝑛=5, so your new value of 𝑛 will be equal to 𝑛=10, after that, you should add 𝑓(10)=2 to 10, so your new (and the final!) value of 𝑛 will be equal to 12.

Orac may ask you these queries many times.

Input
The first line of the input is a single integer 𝑡 (1≤𝑡≤100): the number of times that Orac will ask you.

Each of the next 𝑡 lines contains two positive integers 𝑛,𝑘 (2≤𝑛≤106,1≤𝑘≤109), corresponding to a query by Orac.

It is guaranteed that the total sum of 𝑛 is at most 106.

Output
Print 𝑡 lines, the 𝑖-th of them should contain the final value of 𝑛 in the 𝑖-th query by Orac.

Example
inputCopy
3
5 1
8 2
3 4
outputCopy
10
12
12
Note
In the first query, 𝑛=5 and 𝑘=1. The divisors of 5 are 1 and 5, the smallest one except 1 is 5. Therefore, the only operation adds 𝑓(5)=5 to 5, and the result is 10.

In the second query, 𝑛=8 and 𝑘=2. The divisors of 8 are 1,2,4,8, where the smallest one except 1 is 2, then after one operation 8 turns into 8+(𝑓(8)=2)=10. The divisors of 10 are 1,2,5,10, where the smallest one except 1 is 2, therefore the answer is 10+(𝑓(10)=2)=12.

In the third query, 𝑛 is changed as follows: 3→6→8→10→12.

A

题意:每次给这个数加一个最小公约数,1除外,问+k次后结果为多少

题解:第一次加的时候直接加最小公倍数即可,之后一定为2的倍数,所以加(k-1)*2即为答案。。

随手开ll,

代码:

#include<iostream>
using namespace std;
typedef long long ll;
ll fun(ll x)
{
	for(ll i=2;i*i<=x;i++)
	{
		if(x%i==0)
			return i;
	}
	return x;
}
int main()
{
	int t;
	ll n,k,temp;
	cin>>t;
	
	while(t--)
	{
		cin>>n>>k;
		ll ans=n+fun(n)+(k-1)*2;
		cout<<ans<<endl;
	}
	return 0;
}

B. Orac and Models
time limit per test3 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
There are 𝑛 models in the shop numbered from 1 to 𝑛, with sizes 𝑠1,𝑠2,…,𝑠𝑛.

Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes).

Orac thinks that the obtained arrangement is beatiful, if for any two adjacent models with indices 𝑖𝑗 and 𝑖𝑗+1 (note that 𝑖𝑗<𝑖𝑗+1, because Orac arranged them properly), 𝑖𝑗+1 is divisible by 𝑖𝑗 and 𝑠𝑖𝑗<𝑠𝑖𝑗+1.

For example, for 6 models with sizes {3,6,7,7,7,7}, he can buy models with indices 1, 2, and 6, and the obtained arrangement will be beautiful. Also, note that the arrangement with exactly one model is also considered beautiful.

Orac wants to know the maximum number of models that he can buy, and he may ask you these queries many times.

Input
The first line contains one integer 𝑡 (1≤𝑡≤100): the number of queries.

Each query contains two lines. The first line contains one integer 𝑛 (1≤𝑛≤100000): the number of models in the shop, and the second line contains 𝑛 integers 𝑠1,…,𝑠𝑛 (1≤𝑠𝑖≤109): the sizes of models.

It is guaranteed that the total sum of 𝑛 is at most 100000.

Output
Print 𝑡 lines, the 𝑖-th of them should contain the maximum number of models that Orac can buy for the 𝑖-th query.

Example
inputCopy
4
4
5 3 4 6
7
1 4 2 3 6 4 9
5
5 4 3 2 1
1
9
outputCopy
2
3
1
1
Note
In the first query, for example, Orac can buy models with indices 2 and 4, the arrangement will be beautiful because 4 is divisible by 2 and 6 is more than 3. By enumerating, we can easily find that there are no beautiful arrangements with more than two models.

In the second query, Orac can buy models with indices 1, 3, and 6. By enumerating, we can easily find that there are no beautiful arrangements with more than three models.

In the third query, there are no beautiful arrangements with more than one model.

B

题意:
一个串,找出满足下标i,j;i<j;a[i]<a[j]且j%i==0的一个最长子串,输出其长度

题解:
找出转移方程,每次+i,然后判断后者是否更大,若更大状态转移dp[i] = max(dp[i],dp[j]+1)

代码:

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=1e5+7;
int a[maxn],dp[maxn];
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		for(int i=1;i<=n;i++) cin>>a[i];
		int ans=0;
		for(int i=n;i>=1;i--)
		{
			dp[i]=1;
			for(int j=i;j<=n;j+=i)
			{
				if(a[j]>a[i])
					dp[i]=max(dp[i],dp[j]+1);
			}
			ans=max(dp[i],ans);
		}
		cout<<ans<<endl;
	}
	return 0;
}

额:不打比赛真会变捞

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值