Codeforces Round #520 (Div. 2)

Codeforces Round #520 (Div. 2)

【小结】:

昨晚,真的太困了,我真的没有心机去做了,后来就睡着了。。。睡觉误事呀。。

但是早上起来做这么A-D下来,除了D题翻译出现毛病之外,还是很好做的,

其中B题是个实打实的数论题,C题是一个找规律的一道题。

所以说,不能怕麻烦,不能怕困难,一定要向各位大佬看齐,不会做看题解也要把他看懂。

不会的知识点,赶紧补一补,不要等明天,明日复明日,明日何其多。


A. A Prank

JATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array ?1a1, ?2a2, ..., ??an of integers, such that 1≤?1<?2<…<??≤1031≤a1<a2<…<an≤103, and then went to the bathroom.

JATC decided to prank his friend by erasing some consecutive elements in the array. Since he doesn't want for the prank to go too far, he will only erase in a way, such that Giraffe can still restore the array using the information from the remaining elements. Because Giraffe has created the array, he's also aware that it's an increasing array and all the elements are integers in the range [1,103][1,103].

JATC wonders what is the greatest number of elements he can erase?

Input

The first line of the input contains a single integer ?n (1≤?≤1001≤n≤100) — the number of elements in the array.

The second line of the input contains ?n integers ??ai (1≤?1<?2<⋯<??≤1031≤a1<a2<⋯<an≤103) — the array written by Giraffe.

Output

Print a single integer — the maximum number of consecutive elements in the array that JATC can erase.

If it is impossible to erase even a single element, print 00.

 

input

6
1 3 4 5 6 9

output

2

input

3
998 999 1000

output

2

input

5
1 2 3 4 5

output

4

Note

In the first example, JATC can erase the third and fourth elements, leaving the array [1,3,_,_,6,9][1,3,_,_,6,9]. As you can see, there is only one way to fill in the blanks.

In the second example, JATC can erase the second and the third elements. The array will become [998,_,_][998,_,_]. Because all the elements are less than or equal to 10001000, the array is still can be restored. Note, that he can't erase the first 22 elements.

In the third example, JATC can erase the first 44 elements. Since all the elements are greater than or equal to 11, Giraffe can still restore the array. Note, that he can't erase the last 44 elements.


【题解】:

首先需要翻译一波,不然我也不会无脑WA了,

翻译:JATC想作弄长颈鹿,一连串n个数,然后JATC就抹去了几个数(必须连续)。

但是他还有良心的,想让长颈鹿知道抹去了多少个数,能让他“找回来”。

看例1:发现如果这段连续在中间,不能抹去前后两端。

看例2,例3:发现如果是  最前面 的 1  或者最后面的 1000 构成的连续,可以抹去一端留下一端。

然后答案是抹去的最大值。

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int a[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    int tmp=1,ans=0,maxz=0;
    for(int i=1;i<n;i++){

        if(a[i]-a[i-1]==1){
            //printf("a[%d] : %d tmp : %d\n",i,a[i],tmp);
            tmp++;
            if(a[i-1]==1||a[i]==1000){
                tmp++;
            }
            if(i==n-1){
                ans=ans+max(tmp-2,0);
                maxz=max(maxz,ans);
            }
        }else{
            ans=ans+max(tmp-2,0);
            tmp=1;
            maxz=max(maxz,ans);
            ans=0;
        }
    }
    printf("%d\n",maxz);
}

B. Math

JATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is as follows. Given an integer ?n, you can perform the following operations zero or more times:

  • mul ?x: multiplies ?n by ?x (where ?x is an arbitrary positive integer).
  • sqrt: replaces ?n with ?√n (to apply this operation, ?√n must be an integer).

You can perform these operations as many times as you like. What is the minimum value of ?n, that can be achieved and what is the minimum number of operations, to achieve that minimum value?

Apparently, no one in the class knows the answer to this problem, maybe you can help them?

Input

The only line of the input contains a single integer ?n (1≤?≤1061≤n≤106) — the initial number.

Output

Print two integers: the minimum integer ?n that can be achieved using the described operations and the minimum number of operations required.

Examples

input

20

output

10 2

input

5184

output

6 4

Note

In the first example, you can apply the operation mul 55 to get 100100 and then sqrt to get 1010.

In the second example, you can first apply sqrt to get 7272, then mul 1818 to get 12961296 and finally two more sqrt and you get 66.

Note, that even if the initial value of ?n is less or equal 106106, it can still become greater than 106106 after applying one or more operations.


【题解】:

这个是一道实打实的数论题目,考察的是质因数分解。【详细可百度-唯一分解定理】

问题是:给你一个数n,然后有两种操作,第一个操作是 :乘以X(任意的正整数),第二个操作是:开平方。

然后问,通过这两个操作,你能得到的最小值是什么?其中最小需要多少步?

就是这么两问。

首先我们可以得知,第一问的答案肯定是:质因数之积。

为什么呢,因为通过平方只能把一些质因数所带有的次方降下来,而不能删去这个质因数。

第二问,其实就是模仿事例2即可,首先能降下来尽量降——意思是:所有的质因数的指数部分都是偶数,

然后通过乘以X来弥补一下(使其达到所有质因数的指数都是2的次幂),最后不断开平方,得到我们想要的答案。

详细可以看代码。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000;
ll prime[N],b[N];
ll gcd(ll a,ll b){
    return a%b==0?b:gcd(b,a%b);
}
ll check(ll x){
    for(ll i=22;i>=1;i--){
        if(x%(1ll<<i)==0){
            return i;
        }
    }
    return 0;
}
int solve(ll x){
    for(int i=0;i<22;i++){
        if((1ll<<i)>=x){
            return i;
        }
    }
}
int main()
{
    ll n,t,cnt=0;
    scanf("%lld",&n);
    if(n==1){
        return 0*printf("1 0\n");
    }
    t=n;
    for(ll i=2;i*i<=t;i++){
        if(t%i==0){
            int tot=0;
            prime[cnt]=i;
            while(t%i==0){
                t/=i;
                tot++;
            }
            b[cnt++]=tot;
        }
    }
    if(t!=1){
        prime[cnt]=t;
        b[cnt++]=1;
    }
    /*for(int i=0;i<cnt;i++){
        printf("prime  %lld  :  %lld \n",prime[i],b[i]);
    }*/
    ll GCD=b[0],ans_x=prime[0];
    for(int i=1;i<cnt;i++){
        ans_x=ans_x*prime[i];
        GCD=gcd(GCD,b[i]);
    }
    //printf("GCD  : %lld\n",GCD);
    int ans=check(GCD),tmp=0;
    //printf("check (GCD) : %d\n",ans);
    for(int i=0;i<cnt;i++){
        int tt=solve(b[i]/(1ll<<ans));
        if(tt==0)continue;
        tmp=max(tmp,tt);
    }
    if(tmp){
        ans=ans+tmp+1;
    }
    printf("%lld %d\n",ans_x,ans);
}

C. Banh-mi

JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way.

First, he splits the Banh-mi into ?n parts, places them on a row and numbers them from 11 through ?n. For each part ?i, he defines the deliciousness of the part as ??∈{0,1}xi∈{0,1}. JATC's going to eat those parts one by one. At each step, he chooses arbitrary remaining part and eats it. Suppose that part is the ?i-th part then his enjoyment of the Banh-mi will increase by ??xi and the deliciousness of all the remaining parts will also increase by ??xi. The initial enjoyment of JATC is equal to 00.

For example, suppose the deliciousness of 33 parts are [0,1,0][0,1,0]. If JATC eats the second part then his enjoyment will become 11 and the deliciousness of remaining parts will become [1,_,1][1,_,1]. Next, if he eats the first part then his enjoyment will become 22 and the remaining parts will become [_,_,2][_,_,2]. After eating the last part, JATC's enjoyment will become 44.

However, JATC doesn't want to eat all the parts but to save some for later. He gives you ?q queries, each of them consisting of two integers ??li and ??ri. For each query, you have to let him know what is the maximum enjoyment he can get if he eats all the parts with indices in the range [??,??][li,ri] in some order.

All the queries are independent of each other. Since the answer to the query could be very large, print it modulo 109+7109+7.

Input

The first line contains two integers ?n and ?q (1≤?,?≤1000001≤n,q≤100000).

The second line contains a string of ?n characters, each character is either '0' or '1'. The ?i-th character defines the deliciousness of the ?i-th part.

Each of the following ?q lines contains two integers ??li and ??ri (1≤??≤??≤?1≤li≤ri≤n) — the segment of the corresponding query.

Output

Print ? lines, where ?-th of them contains a single integer — the answer to the ?-th query modulo 1e9+7.

Examples

input

4 2
1011
1 4
3 4

output

14
3

input

3 2
111
1 2
3 3

output

3
1

Note

In the first example:

  • For query 11: One of the best ways for JATC to eats those parts is in this order: 11, 44, 33, 22.
  • For query 22: Both 33, 44 and 44, 33 ordering give the same answer.

In the second example, any order of eating parts leads to the same answer.


【题意】:

这个题目有点意思,其实只要翻译下来,然后在草稿纸写一写就会发现规律了。

翻译:

给你N,Q,长度为N的01串,Q次询问的 [ L , R ];

1、如果拿走某一个位置上的一个数,ans+=这个数;

2、那么,串中剩下来的,都需要加上这个数。

然后问你怎么拿在这个区间上才会有最大值。

【题解】:

非常感谢博主:https://blog.csdn.net/qq_38891827/article/list/1?t=1

所提供的翻译,我只是仅仅看了看翻译。

后来我想,不就是贪心呗,先把1的都拿了,然后拿0

然后这个数也很特别,居然和二进制有关系,匪夷所思。

你在区域上拿了多少个1,其实也相当于不断地加权。

后来发现其实就是一个二进制数罢了,不过要用快速幂。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int N=2e5+100;
ll qpow(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1){
            ans=ans*a%mod;
        }
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
int a[N];
int sum[N];
int main()
{
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++){
        scanf("%1d",&a[i]);
    }
    for(int i=1;i<=n;i++){
        sum[i]=sum[i-1]+a[i];
    }
    while(q--){
        int L,R;
        scanf("%d%d",&L,&R);
        int len=R-L+1;
        int one=sum[R]-sum[L-1];
        int zero=len-one;
        ll t1,t2,ans;
        t1=(qpow(2,one)-1+mod)%mod;
        t2=(qpow(2,zero)-1+mod)%mod;
        ans=(t1+(t2*t1)%mod)%mod;
        printf("%lld\n",ans);
    }
    return 0;
}

D. Fun with Integers

You are given a positive integer ?n greater or equal to 22. For every pair of integers ?a and ?b (2≤|?|,|?|≤?2≤|a|,|b|≤n), you can transform ?a into ?b if and only if there exists an integer ?x such that 1<|?|1<|x| and (?⋅?=?a⋅x=b or ?⋅?=?b⋅x=a), where |?||x| denotes the absolute value of ?x.

After such a transformation, your score increases by |?||x| points and you are not allowed to transform ?a into ?b nor ?b into ?a anymore.

Initially, you have a score of 00. You can start at any integer and transform it as many times as you like. What is the maximum score you can achieve?

Input

A single line contains a single integer ?n (2≤?≤1000002≤n≤100000) — the given integer described above.

Output

Print an only integer — the maximum score that can be achieved with the transformations. If it is not possible to perform even a single transformation for all possible starting integers, print 00.

input

4

output

8

input

6

output

28

input

2

output

0

Note

In the first example, the transformations are 2→4→(−2)→(−4)→22→4→(−2)→(−4)→2.

In the third example, it is impossible to perform even a single transformation.


【题意】:

只要你搞懂题意,这个题就是一个水题,题目说,给你一个N,然后让你去找  2<=abs(a), (b)<=N

在N内找到一组a,b然后找到他们的倍数关系  : X ,答案就是所有abs(x)之和。

很简单吧,枚举即可。个人认为,放在A题的位置肯定有2000+的人做出来。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,ans=0;
    scanf("%lld",&n);
    for(ll i=2;i<=n/2;i++){
        for(ll j=2;i*j<=n;j++){
            ans+=j*4;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

 

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值