Multiples of Length CodeForces - 1396A
原题链接
考察:构造
思路:
对于n,如果每次x都能+-(n-1)的倍数,那么一定可以使x变成n的倍数.
\[x = n*x-(n-1)*x
\]
\[x+(n-1)x = n*x
\]
由此这三步为:
- 使a[1~n-1]变为n的倍数
- 使a[n]变成0
- 使a[1~n]变成0
Code
#include <iostream>
#include <cstring>
using namespace std;
typedef long long LL;
const int N = 100010;
int n;
LL a[N];
void solve()
{
if(n==1)
{
printf("%d %d\n%lld\n",1,1,-a[1]);
printf("%d %d\n0\n",1,1);
printf("%d %d\n0\n",1,1);
return;
}
printf("%d %d\n",1,n-1);
for(int i=1;i<n;i++)
{
printf("%lld ",(n-1)*a[i]);
a[i]+=(n-1)*a[i];
}
printf("\n%d %d\n%lld\n",n,n,-a[n]);
a[n] = 0;
printf("%d %d\n",1,n);
for(int i=1;i<=n;i++)
printf("%lld ",-a[i]);
printf("\n");
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
solve();
return 0;
}