A. Nastia and Nearly Good Numbers
题意:构造三个数x,y, z,一个数被ab整除,另外两个数能被a整除,但不能被ab整除。因为都有a,可以将a先除掉。
要求z = x + y,b = b - 1 + 1
三个数ab, a(b-1),a
当b等于1的时候,无法构造,因为能被a整除的数也能被ab整除
能发现 b=2 时,有两个数相等,所以换成这样的三个数。
a(b+1),a,a*b。
#include <bits/stdc++.h>
using namespace std;
const int N = 5050;
typedef long long ll;
typedef pair<int, int> PII;
int t;
ll a, b;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t -- )
{
cin >> a >> b;
if (b == 1)
{
puts("NO");
continue;
}
else
{
puts("YES");
printf("%lld %lld %lld\n", a, a * b, a * (b + 1));
}
}
return 0;
}
B. Nastia and a Good Array
要保证相邻的数都是质数,我们取两个相邻的数,把大的那个数改成小的那个数加1,但是再改下去是不行的,因为随着改动各个数的大小关系在变化,所以每次改动取最小的数mi,把它旁边的数改为mi + 1, mi + 2,mi +3…
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
const int N = 1e5 + 5;
typedef long long ll;
typedef pair<int, int> PII;
int t, n;
ll a[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t -- )
{
cin >> n;
for (int i = 1; i <= n; i ++ ) cin >> a[i];
int pos, mi = INF;
for (int i = 1; i <= n; i ++ )
{
if (a[i] < mi) pos = i, mi = a[i];
}
cout << n - 1 << endl;
for (int i = 1; i < pos; i ++ )
cout << i << ' ' << pos << ' ' << mi + pos - i << ' ' << mi << endl;
for (int i = pos + 1; i <= n; i ++ )
cout << i << ' ' << pos << ' ' << mi + i - pos << ' ' << mi << endl;
}
return 0;
}