【比赛报告】 Codeforces Round #512 (Div. 2, based on Technocup 2019 Elimination Round 1) NOIP练习赛卷四

比赛链接

A.In Search of an Easy Problem

Description

When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as possible. This time the coordinator had chosen some problem and asked n people about their opinions. Each person answered whether this problem is easy or hard.

If at least one of these n people has answered that the problem is hard, the coordinator decides to change the problem. For the given responses, check if the problem is easy enough.

Input

The first line contains a single integer n (1≤n≤100) — the number of people who were asked to give their opinions.

The second line contains n integers, each integer is either 0 or 1. If i-th integer is 0, then i-th person thinks that the problem is easy; if it is 1, then i-th person thinks that the problem is hard.

Output

Print one word: “EASY” if the problem is easy according to all responses, or “HARD” if there is at least one person who thinks the problem is hard.

You may print every letter in any register: “EASY”, “easy”, “EaSY” and “eAsY” all will be processed correctly.

Examples

Input

3
0 0 1

Output

HARD

Input

1
0

Output

EASY

Note

In the first example the third person says it’s a hard problem, so it should be replaced.

In the second example the problem easy for the only person, so it doesn’t have to be replaced.


#include<cstdio>
int main()
{
	int n,a;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		if(a==1)return puts("HARD"),0;
	}
	return puts("EASY"),0;
}

总结


B.Vasya and Cornfield

Description

Vasya owns a cornfield which can be defined with two integers n and d. The cornfield can be represented as rectangle with vertices having Cartesian coordinates (0,d),(d,0),(n,n−d) and (n−d,n).
在这里插入图片描述
An example of a cornfield with n=7 and d=2.
Vasya also knows that there are m grasshoppers near the field (maybe even inside it). The i-th grasshopper is at the point (xi,yi). Vasya does not like when grasshoppers eat his corn, so for each grasshopper he wants to know whether its position is inside the cornfield (including the border) or outside.

Help Vasya! For each grasshopper determine if it is inside the field (including the border).

Input

The first line contains two integers n and d (1≤d<n≤100).

The second line contains a single integer m (1≤m≤100) — the number of grasshoppers.

The i-th of the next m lines contains two integers xi and yi (0≤xi,yi≤n) — position of the i-th grasshopper.

Output

Print m lines. The i-th line should contain “YES” if the position of the i-th grasshopper lies inside or on the border of the cornfield. Otherwise the i-th line should contain “NO”.

You can print each letter in any case (upper or lower).

Examples

Input

7 2
4
2 4
4 1
6 3
4 5

Output

YES
NO
NO
YES

Input

8 7
4
4 4
2 8
8 1
6 1

Output

YES
NO
YES
YES

Note

The cornfield from the first example is pictured above. Grasshoppers with indices 1 (coordinates (2,4)) and 4 (coordinates (4,5)) are inside the cornfield.

The cornfield from the second example is pictured below. Grasshoppers with indices 1 (coordinates (4,4)), 3 (coordinates (8,1)) and 4 (coordinates (6,1)) are inside the cornfield.
在这里插入图片描述


一道线性规划题。 ∀ p ( x , y ) \forall p(x,y) p(x,y),点 p p p 在四条直线围成的矩形中,当且仅当 x , y x,y x,y 满足以下约束条件:
{ x + y − d ≥ 0 x + y − 2 n + d ≤ 0 x − y − d ≤ 0 x − y + d ≥ 0 \begin{cases}x+y-d\geq0\\x+y-2n+d\leq0\\x-y-d\leq0\\x-y+d\geq0\end{cases} x+yd0x+y2n+d0xyd0xy+d0
然后读入每个点判断就行了。

#include<cstdio>
int main()
{
	//freopen("in.txt","r",stdin);
	int n,d,x,y,m;
	scanf("%d%d%d",&n,&d,&m);
	while(m--)
	{
		scanf("%d%d",&x,&y);
		if(x+y-d<0||x+y-2*n+d>0||x-y-d>0||x-y+d<0)puts("NO");
		else puts("YES");
	}
	return 0;
}

总结

我不碰数学好多年


C.Vasya and Golden Ticket

Description

Recently Vasya found a golden ticket — a sequence which consists of n n n digits a 1 a 2 ⋯ a n ‾ \overline{a_1a_2\cdots a_n} a1a2an. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket 350178 350178 350178 is lucky since it can be divided into three segments 350 350 350, 17 17 17 and 8 8 8: 3 + 5 + 0 = 1 + 7 = 8 3+5+0=1+7=8 3+5+0=1+7=8. Note that each digit of sequence should belong to exactly one segment.

Help Vasya! Tell him if the golden ticket he found is lucky or not.

Input

The first line contains one integer n n n ( 2 ≤ n ≤ 100 2≤n≤100 2n100) — the number of digits in the ticket.

The second line contains n n n digits a 1 a 2 ⋯ a n ‾ \overline{a_1a_2\cdots a_n} a1a2an ( 0 ≤ a i ≤ 9 0≤a_i≤9 0ai9) — the golden ticket. Digits are printed without spaces.

Output

If the golden ticket is lucky then print “YES”, otherwise print “NO” (both case insensitive).

Examples

Input

5
73452

Output

YES

Input

4
1248

Output

NO

Note

In the first example the ticket can be divided into 7 7 7, 34 34 34 and 52 52 52: 7 = 3 + 4 = 5 + 2 7=3+4=5+2 7=3+4=5+2.

In the second example it is impossible to divide ticket into segments with equal sum.


区间DP。设 F [ p o s ] F[pos] F[pos] 表示 p o s pos pos 位是否可以作为一段的结尾。

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int n,sum[110];
bool f[110];
char ch;
int main()
{
    std::ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>ch,sum[i]=sum[i-1]+ch-'0';
    if(sum[n]==0)return puts("YES"),0;
	for(int i=0;i<sum[n];i++)
    {
    	memset(f,false,sizeof(f));
    	f[0]=true;
    	for(int t=1;t<=n;t++)
    	    for(int h=t;h;h--)
    	        if(f[h-1]&&sum[t]-sum[h-1]==i)
    	            f[t]=true;
    	if(f[n]==true)return puts("YES"),0;
	}
	return puts("NO"),0;
}

总结

原本想暴力的,结果错了……刚好写写DP


D.Vasya and Triangle

题目链接

Description

Vasya has got three integers n n n, m m m and k k k. He’d like to find three integer points ( x 1 , y 1 ) (x_1,y_1) (x1,y1), ( x 2 , y 2 ) (x_2,y_2) (x2,y2), ( x 3 , y 3 ) (x_3,y_3) (x3,y3), such that 0 ≤ x 1 , x 2 , x 3 ≤ n 0≤x_1,x_2,x_3≤n 0x1,x2,x3n, 0 ≤ y 1 , y 2 , y 3 ≤ m 0≤y_1,y_2,y_3≤m 0y1,y2,y3m and the area of the triangle formed by these points is equal to nmk.

Help Vasya! Find such points (if it’s possible). If there are multiple solutions, print any of them.

Input

The single line contains three integers n n n, m m m, k k k ( 1 ≤ n , m ≤ 1 0 9 , 2 ≤ k ≤ 1 0 9 ) (1≤n,m≤10^9, 2≤k≤10^9) (1n,m109,2k109).

Output

If there are no such points, print “NO”.

Otherwise print “YES” in the first line. The next three lines should contain integers x i , y i x_i,y_i xi,yi — coordinates of the points, one point per line. If there are multiple solutions, print any of them.

You can print each letter in any case (upper or lower).

Examples

Input

4 3 3

Output

YES
1 0
2 3
4 1

Input

4 4 7

Output

NO

Note

In the first example area of the triangle should be equal to n × m k = 4 \frac{n\times m}{k}=4 kn×m=4. The triangle mentioned in the output is pictured below:

In the second example there is no triangle with area n × m k = 16 7 \frac{n\times m}{k}=\frac{16}{7} kn×m=716.


让第一个点落在原点,第二个点落在 x x x 轴,第三个点落在 y y y 轴,即三个点的坐标为 ( 0 , 0 ) , ( x , 0 ) , ( 0 , y ) (0,0),(x,0),(0,y) (0,0),(x,0),(0,y),面积 S = x × y 2 S=\frac{x\times y}{2} S=2x×y。化简可得 x × y = 2 × n × m k x\times y=\frac{2\times n\times m}{k} x×y=k2×n×m,即 k ∣ 2 × n × m k\mid 2\times n\times m k2×n×m g c d gcd gcd 即可求解。

#include<cstdio>
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main()
{
    ll n,m,k;bool div=false;
    scanf("%lld%lld%lld",&n,&m,&k);
    if(2*n*m%k)return puts("NO"),0;
    if(k%2==0)k/=2,div=true;
    ll g=gcd(n,k);k/=g;
    ll x=n/g,y=m/k;
    if(!div)if(2*x<n)x*=2;else y*=2;
    printf("YES\n0 0\n%lld 0\n0 %lld\n",x,y);
    return 0;
}

总结

又考数学


E.Vasya and Good Sequences

Description

Vasya has a sequence a consisting of n n n integers a 1 , a 2 , ⋯ &ThinSpace; , a n a_1,a_2,\cdots,a_n a1,a2,,an. Vasya may pefrom the following operation: choose some number from the sequence and swap any pair of bits in its binary representation. For example, Vasya can transform number 6 6 6 ( ⋯ 0000000011 0 2 ) (\cdots00000000110_2) (000000001102) into 3 3 3 ( ⋯ 0000000001 1 2 ) (\cdots00000000011_2) (000000000112), 12 12 12 ( ⋯ 00000000110 0 2 ) (\cdots000000001100_2) (0000000011002), 1026 1026 1026 ( ⋯ 1000000001 0 2 ) (\cdots10000000010_2) (100000000102) and many others. Vasya can use this operation any (possibly zero) number of times on any number from the sequence.

Vasya names a sequence as good one, if, using operation mentioned above, he can obtain the sequence with bitwise exclusive or of all elements equal to 0 0 0.

For the given sequence a 1 , a 2 , ⋯ &ThinSpace; , a n a_1,a_2,\cdots,a_n a1,a2,,an Vasya’d like to calculate number of integer pairs ( l , r ) (l,r) (l,r) such that 1 ≤ l ≤ r ≤ n 1≤l≤r≤n 1lrn and sequence a l , a l + 1 , ⋯ &ThinSpace; , a r a_l,a_{l+1},\cdots,a_r al,al+1,,ar is good.

Input

The first line contains a single integer n n n ( 1 ≤ n ≤ 3 × 1 0 5 ) (1≤n≤3\times10^5) (1n3×105) — length of the sequence.

The second line contains n n n integers a 1 , a 2 , ⋯ &ThinSpace; , a n a_1,a_2,\cdots,a_n a1,a2,,an ( 1 ≤ a i ≤ 1 0 18 ) (1≤a_i≤10^{18}) (1ai1018) — the sequence a.

Output

Print one integer — the number of pairs ( l , r ) (l,r) (l,r) such that 1 ≤ l ≤ r ≤ n 1≤l≤r≤n 1lrn and the sequence a l , a l + 1 , ⋯ &ThinSpace; , a r a_l,a_{l+1},\cdots,a_r al,al+1,,ar is good.

Examples

Input

3
6 7 14

Output

2

Input

4
1 2 1 16

Output

4

Note

In the first example pairs ( 2 , 3 ) (2,3) (2,3) and ( 1 , 3 ) (1,3) (1,3) are valid. Pair ( 2 , 3 ) (2,3) (2,3) is valid since a 2 = 7 → 11 a_2=7→11 a2=711, a 3 = 14 → 11 a_3=14→11 a3=1411 and 11 ⊕ 11 = 0 11⊕11=0 1111=0, where ⊕ ⊕ — bitwise exclusive or. Pair ( 1 , 3 ) (1,3) (1,3) is valid since a 1 = 6 → 3 a_1=6→3 a1=63, a 2 = 7 → 13 a_2=7→13 a2=713, a 3 = 14 → 14 a_3=14→14 a3=1414 and 3 ⊕ 13 ⊕ 14 = 0 3⊕13⊕14=0 31314=0.

In the second example pairs ( 1 , 2 ) (1,2) (1,2), ( 2 , 3 ) (2,3) (2,3), ( 3 , 4 ) (3,4) (3,4) and ( 1 , 4 ) (1,4) (1,4) are valid.


一个区间内想要异或得到 0 0 0,该区间内 1 1 1 要有偶数个,且 1 1 1 最多的数不能超过和的一半。
c n t [ 0 ] [ i ] cnt[0][i] cnt[0][i] 表示 i ∼ n i\sim n in中偶数个 1 1 1 的后缀和, c n t [ 1 ] [ i ] cnt[1][i] cnt[1][i] 同理。

#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=3e5+10;
int n;
ll a[N],cnt[2][N];
inline int getone(ll x){int ret=0;while(x)ret++,x-=x&-x;return ret;}
int main()
{
	//freopen("in.txt","r",stdin);
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%lld",&a[i]),a[i]=getone(a[i]);
    cnt[0][n]=1;
    ll ans=0,sum=0;
    for(int i=n-1;i>=0;i--)
    {
    	ll onesum=0,maxn=0,pir=0;
    	for(int j=i;j<n&&j-i<65;j++)
    	{
    		onesum+=a[j];maxn=max(maxn,a[j]);
    		if(maxn*2>onesum&&onesum%2==0)pir--;
		}
		sum+=a[i];pir+=cnt[sum&1][i+1];ans+=pir;
		cnt[0][i]=cnt[0][i+1];
		cnt[1][i]=cnt[1][i+1];
		if(sum&1)cnt[1][i]++;
		else cnt[0][i]++;
	}
	printf("%lld\n",ans);
	return 0;
}

总结

学了一波骚操作


F.Putting Boxes Together

题目链接

Description

There is an infinite line consisting of cells. There are n boxes in some cells of this line. The i t h i_{th} ith box stands in the cell a i a_i ai and has weight w i w_i wi. All a i a_i ai are distinct, moreover, a i − 1 &lt; a i a_{i−1}&lt;a_i ai1<ai holds for all valid i i i.

You would like to put together some boxes. Putting together boxes with indices in the segment [ l , r ] [l,r] [l,r] means that you will move some of them in such a way that their positions will form some segment 4[x,x+(r−l)]$.

In one step you can move any box to a neighboring cell if it isn’t occupied by another box (i.e. you can choose i i i and change a i a_i ai by 1 1 1, all positions should remain distinct). You spend w i w_i wi units of energy moving the box i i i by one cell. You can move any box any number of times, in arbitrary order.

Sometimes weights of some boxes change, so you have queries of two types:

i d id id n w nw nw — weight w i d w_{id} wid of the box i d id id becomes n w nw nw.
l l l r r r — you should compute the minimum total energy needed to put together boxes with indices in [ l , r ] [l,r] [l,r]. Since the answer can be rather big, print the remainder it gives when divided by 1000000007 = 1 0 9 + 7 1000000007=10^9+7 1000000007=109+7. Note that the boxes are not moved during the query, you only should compute the answer.
Note that you should minimize the answer, not its remainder modulo 1 0 9 + 7 10^9+7 109+7. So if you have two possible answers 2 ⋅ 1 0 9 + 13 2⋅10^9+13 2109+13 and 2 ⋅ 1 0 9 + 14 2⋅10^9+14 2109+14, you should choose the first one and print 1 0 9 + 6 10^9+6 109+6, even though the remainder of the second answer is 0 0 0.

Input

The first line contains two integers n n n and q q q ( 1 ≤ n , q ≤ 2 × 1 0 5 ) (1≤n,q≤2\times10^5) (1n,q2×105) — the number of boxes and the number of queries.

The second line contains n n n integers a 1 , a 2 , ⋯ &ThinSpace; , a n a_1,a_2,\cdots,a_n a1,a2,,an ( 1 ≤ a i ≤ 1 0 9 ) (1≤a_i≤10^9) (1ai109) — the positions of the boxes. All ai are distinct, a i − 1 &lt; a i a_{i−1}&lt;a_i ai1<ai holds for all valid i i i.

The third line contains n n n integers w 1 , w 2 , ⋯ &ThinSpace; , w n w_1,w_2,\cdots,w_n w1,w2,,wn ( 1 ≤ w i ≤ 1 0 9 ) (1≤w_i≤10^9) (1wi109) — the initial weights of the boxes.

Next q q q lines describe queries, one query per line.

Each query is described in a single line, containing two integers x x x and y y y. If x &lt; 0 x&lt;0 x<0, then this query is of the first type, where i d = − x id=−x id=x, n w = y nw=y nw=y ( 1 ≤ i d ≤ n , 1 ≤ n w ≤ 1 0 9 ) (1≤id≤n, 1≤nw≤10^9) (1idn,1nw109). If x &gt; 0 x&gt;0 x>0, then the query is of the second type, where l = x l=x l=x and r = y r=y r=y ( 1 ≤ l j ≤ r j ≤ n ) (1≤l_j≤r_j≤n) (1ljrjn). x x x can not be equal to 0 0 0.

Output

For each query of the second type print the answer on a separate line. Since answer can be large, print the remainder it gives when divided by 1000000007 = 1 0 9 + 7 1000000007=10^9+7 1000000007=109+7.

Example

Input

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

Output

0
10
3
4
18
7

Note

Let’s go through queries of the example:

1 1 1\quad1 11 — there is only one box so we don’t need to move anything.
1 5 1\quad 5 15 — we can move boxes to segment [ 4 , 8 ] : 1 × ∣ 1 − 4 ∣ + 1 × ∣ 2 − 5 ∣ + 1 × ∣ 6 − 6 ∣ + 1 × ∣ 7 − 7 ∣ + 2 × ∣ 10 − 8 ∣ = 10 [4,8]: 1\times|1−4|+1\times|2−5|+1\times|6−6|+1\times|7−7|+2\times|10−8|=10 [4,8]:1×14+1×25+1×66+1×77+2×108=10.
1 3 1\quad 3 13 — we can move boxes to segment [ 1 , 3 ] [1,3] [1,3].
3 5 3\quad 5 35 — we can move boxes to segment [ 7 , 9 ] [7,9] [7,9].
− 3 5 −3\quad 5 35 w 3 w_3 w3 is changed from 1 1 1 to 5 5 5.
− 1 10 −1\quad 10 110 w 1 w_1 w1 is changed from 1 1 1 to 10 10 10. The weights are now equal to w = [ 10 , 1 , 5 , 1 , 2 ] w=[10,1,5,1,2] w=[10,1,5,1,2].
1 4 1\quad 4 14 — we can move boxes to segment [ 1 , 4 ] [1,4] [1,4].
2 5 2\quad 5 25 — we can move boxes to segment [ 5 , 8 ] [5,8] [5,8].


第一次遇到带权中位数的题,学习了大佬博客

#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
const int N=2e5+10;
const int mod=1e9+7;
int n,q;
ll a[N],w[N],c[N<<1][2];
inline void add(int x,ll v,int id)
{
	if(!id)for(;x<=n;x+=x&-x)c[x][id]+=v;
	else for(;x<=n;x+=x&-x)c[x][id]=(c[x][id]+v+mod)%mod;
}
inline ll ask(int x,int id)
{
	ll ret=0;
	if(!id)for(;x;x-=x&-x)ret+=c[x][id];
	else for(;x;x-=x&-x)ret=(ret+c[x][id]+mod)%mod;
	return ret;
}
inline ll gets(int x,int y,int id)
{
	if(!id)return y>=x?ask(y,id)-ask(x-1,id):0;
	else return (ask(y,id)-ask(x-1,id)+mod)%mod;
}
inline int bsearch(int x,int y)
{
	int l=x,r=y,mid;
	while(l<r)
	{
		mid=(l+r)/2;
		if(gets(x,mid,0)>=gets(mid+1,y,0))r=mid;
		else l=mid+1;
	}
	return r;
}
int main()
{
	//freopen("in.txt","r",stdin);
    scanf("%d%d",&n,&q);
    for(register int i=1;i<=n;i++)scanf("%lld",&a[i]);
    for(register int i=1;i<=n;i++)scanf("%lld",&w[i]),add(i,w[i],0),add(i,w[i]*(a[i]-i),1);
    while(q--)
    {
    	int x,y;
    	scanf("%d%d",&x,&y);
    	if(x<0)
    	{
    		x=-x;
			add(x,-w[x],0);add(x,-w[x]*(a[x]-x),1);
    		w[x]=y;
    		add(x,w[x],0);add(x,w[x]*(a[x]-x),1);
		}
		else
		{
			if(x==y){puts("0");continue;}
			ll pos=bsearch(x,y),ans=0;
			ans=(ans+(gets(x,pos,0)%mod)*(int)abs(a[pos]-pos)%mod-gets(x,pos,1)+mod)%mod;
		    ans=(ans-(gets(pos,y,0)%mod)*(int)abs(a[pos]-pos)%mod+gets(pos,y,1)+mod)%mod;
		    printf("%lld\n",ans);
		}
	}
	return 0;
}

总结

第一次遇到带权中位数的题,好好学学。


G.Linear Congruential Generator

Description

You are given a tuple generator f ( k ) = ( f 1 ( k ) , f 2 ( k ) , ⋯ &ThinSpace; , f n ( k ) ) f^{(k)}=(f^{(k)}_1,f^{(k)}_2,\cdots,f^{(k)}_n) f(k)=(f1(k),f2(k),,fn(k)), where f i ( k ) = ( a i ⋅ f i ( k − 1 ) + b i ) m o d &ThinSpace;&ThinSpace; p i f^{(k)}_i=(a_i⋅f^{(k−1)}_i+b_i)\mod p_i fi(k)=(aifi(k1)+bi)modpi and f ( 0 ) = ( x 1 , x 2 , ⋯ &ThinSpace; , x n ) f^{(0)}=(x_1,x_2,\cdots,x_n) f(0)=(x1,x2,,xn). Here x m o d &ThinSpace;&ThinSpace; y x\mod y xmody denotes the remainder of x x x when divided by y y y. All p i p_i pi are primes.

One can see that with fixed sequences x i , y i , a i x_i, y_i, a_i xi,yi,ai the tuples $f^{(k)} starting from some index will repeat tuples with smaller indices. Calculate the maximum number of different tuples (from all f ( k ) f^{(k)} f(k) for k ≥ 0 k≥0 k0) that can be produced by this generator, if x i , a i , b i x_i, a_i, b_i xi,ai,bi are integers in the range [ 0 , p i − 1 ] [0,p_i−1] [0,pi1] and can be chosen arbitrary. The answer can be large, so print the remainder it gives when divided by 1 0 9 + 7 10^9+7 109+7

Input

The first line contains one integer n n n ( 1 ≤ n ≤ 2 × 105 ) (1≤n≤2\times105) (1n2×105) — the number of elements in the tuple.

The second line contains n n n space separated prime numbers — the modules p 1 , p 2 , ⋯ &ThinSpace; , p n p_1,p_2,\cdots,p_n p1,p2,,pn ( 2 ≤ p i ≤ 2 × 1 0 6 ) (2≤p_i≤2\times10^6) (2pi2×106).

Output

Print one integer — the maximum number of different tuples modulo 1 0 9 + 7 10^9+7 109+7.

Examples

Input

4
2 3 5 7

Output

210

Input

3
5 3 3

Output

30

Note

In the first example we can choose next parameters: a = [ 1 , 1 , 1 , 1 ] , b = [ 1 , 1 , 1 , 1 ] , x = [ 0 , 0 , 0 , 0 ] a=[1,1,1,1], b=[1,1,1,1], x=[0,0,0,0] a=[1,1,1,1],b=[1,1,1,1],x=[0,0,0,0], then f i ( k ) = k m o d &ThinSpace;&ThinSpace; p i f^{(k)}_i=k\mod p_i fi(k)=kmodpi.

In the second example we can choose next parameters: a = [ 1 , 1 , 2 ] , b = [ 1 , 1 , 0 ] , x = [ 0 , 0 , 1 ] a=[1,1,2], b=[1,1,0], x=[0,0,1] a=[1,1,2],b=[1,1,0],x=[0,0,1].


感觉整道题非常玄学。在围观大佬题解官方题解后,大概明白了啥意思。这个函数图像是一个圆圈还有圈外的一部分。最后答案是 l c m i = 1 ⋯ n ( c i ) lcm_{i=1\cdots n}(c_i) lcmi=1n(ci)+ max ⁡ i = 1 ⋯ n ( p p i ) \max\limits_{i=1\cdots n}(pp_i) i=1nmax(ppi)。中间噼里啪啦一堆公式看的我酸爽,反正就证明了 max ⁡ i = 1 ⋯ n ( p p i ) = 1 \max\limits_{i=1\cdots n}(pp_i)=1% i=1nmax(ppi)=1以及我们需要 p i − 1 p_i-1 pi1 的因子。然后就是求一个 l c m lcm lcm,如果 p i p_i pi 加过了就加 p i − 1 p_i-1 pi1,然后就稀里糊涂写()一遍就过了。

#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2e6+10;
const int mod=1e9+7;
int prime[N],pp,pri[N],ans=1,p[N],n,cnt[N],mx[N];
bool iscomp[N];
void primetable()
{
	for(int i=2;i<N;i++)
	{
		if(!iscomp[i])prime[pp++]=i,pri[i]=i;
		for(int j=0;j<pp&&1ll*i*prime[j]<N;j++)
		{
			iscomp[i*prime[j]]=1;
			pri[i*prime[j]]=prime[j];
			if(i%prime[j]==0)break;
		}
	}
}
int main()
{
	//freopen("in.txt","r",stdin);
	primetable();
	scanf("%d\n",&n);
	for(int i=1;i<=n;i++)scanf("%d",&p[i]);
    sort(p+1,p+n+1);
    for(int i=n;i;i--)
    {
    	if(!cnt[p[i]])cnt[p[i]]++,mx[p[i]]=1,ans=(1ll*ans*p[i])%mod;
    	else
    	{
    		int v=--p[i];
    		while(v!=1)
    		{
    			int u=pri[v],ci=0;
    			while(v%u==0)v/=u,ci++;
    			if(cnt[u]<ci)
    			{
    				for(int j=cnt[u]+1;j<=ci;j++)ans=(1ll*ans*u)%mod;
    				cnt[u]=ci;mx[u]=1;
				}
				else mx[u]+=(cnt[u]==ci);
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		int v=p[i],flag=0;
		while(v!=1)
		{
			int u=pri[v],ci=0;
			while(v%u==0)v/=u,ci++;
			if(cnt[u]==ci&&mx[u]==1)flag=1;
		}
		if(!flag)
		{
			ans++;break;
		}
	}
	printf("%d\n",ans);
	return 0;
}

总结

玄学数论,还有那个啥拉格朗日定理是啥……
在这里插入图片描述


比赛总结

Div.2的比赛题比Div.3要难上不少。感觉这场比赛考了贼多数学知识。带权中位数啥的东西要好好掌握,还有一些别的骚操作啥的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值