Good Bye 2023
A. 2023
思路:如果这些数是2023的因子,只需用1补全原序列即可
code:
void solved()
{
int a = 2023, flag = 0;
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; ++i)
{
int temp;
cin >> temp;
if (a % temp != 0 && flag == 0)
{
cout << "NO" << endl;
flag = 1;
}
else
{
a /= temp;
}
}
if (flag == 0)
{
cout << "YES" << endl;
cout << a << " ";
for (int i = 1; i < k; ++i)
cout << 1 << " ";
cout << endl;
}
}
B. Two Divisors
思路:找出a和b中最小的质因子,和b相乘即可
code:
void Eratosthenes(int n)
{
for (LL i = 2; i <= n; ++i)
{
if (!vis[i])
{
prim[cnt++] = i;
for (LL j = i * i; j <= n; j += i)
vis[j] = 1;
}
}
}
void solved()
{
int a, b;
cin >> a >> b;
for (int i = 0; i < cnt; ++i)
{
if (a % prim[i] == 0 || b % prim[i] == 0)
{
cout << b * prim[i] << endl;
return;
}
}
}
C. Training Before the Olympiad
思路:两个人无论谁操作都会将奇数变偶数,若有奇数,Olya会使总数减一,Masha可以在一次操作中消去两个奇数,只有一个奇数时,无论谁操作都会使总数减一,要开long long
code:
void solved()
{
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> a[i];
}
int odd = 0, even = 0, sum = 0;
for (int i = 1; i <= n; ++i)
{
sum += a[i];
if (a[i] & 1)
odd++;
if (i == 1)
{
cout << sum << " ";
}
else
{
if (odd > 0)
{
int ans = sum - odd / 3;
if (odd % 3 == 1)
ans--;
cout << ans << " ";
}
else
{
cout << sum << " ";
}
}
}
cout << endl;
}
D. Mathematical Problem
思路:可以通过打表发现规律,1,6,9可以构造
code:
void solved()
{
int n;
cin >> n;
if (n == 1)
{
cout << 1 << endl;
return;
}
cout << 196 << string(n - 3, '0') << endl;
for (int i = 0; i < n / 2; ++i)
{
cout << 9 << string(i, '0') << 6 << string(i, '0') << 1 << string(n - 3 - 2 * i, '0') << endl;
cout << 1 << string(i, '0') << 6 << string(i, '0') << 9 << string(n - 3 - 2 * i, '0') << endl;
}
}