A 2023
sequence a, whose product was equal to 2023, k numbers were removed, leaving a sequence b of length n. Given the resulting sequence b, find any suitable sequence a and output which k elements were removed from it, or state that such a sequence could not have existed.
Notice that you are not guaranteed that such array exists.
有解前提为
(
Π
1
n
b
i
)
∣
2023
(\Pi_1^n b_i) | 2023
(Π1nbi)∣2023,加1补足剩余部分。
.
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int a[1000];
void wk(){
int n=read(),k=read();
For(i,n) a[i]=read();
int p=2023;
For(i,n) {
if(p%a[i]) {
puts("NO");return ;
}p/=a[i];
}
puts("YES");
cout<<p;
For(i,k-1) cout<<' '<<1;cout<<endl;
}
int main()
{
// freopen("A.in","r",stdin);
// freopen(".out","w",stdout);
int T=read();
while(T--) {
wk();
}
return 0;
}
B Two Divisors
A certain number
1
≤
x
≤
1
0
9
1≤x≤10^9
1≤x≤109 is chosen. You are given two integers a
and b, which are the two largest divisors of the number x. At the same time, the condition
1
≤
a
<
b
<
x
1≤a<b<x
1≤a<b<x is satisfied.
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
ll gcd(ll a,ll b){
if(!b) return a;return gcd(b,a%b);
}
ll lcm(ll a,ll b){
return a/gcd(a,b)*b;
}
#define MAXN (1000000+10)
int p[MAXN],tot;
bool b[MAXN]={0};
void make_prime(int n)
{
tot=0;
Fork(i,2,n)
{
if (!b[i]) p[++tot]=i;
For(j,tot)
{
if (i*p[j]>n) break;
b[i*p[j]]=1;
if (i%p[j]==0) break;
}
}
}
ll get(ll s) {
For(i,tot) {
if(p[i]>s) return s;
if(s%p[i]==0) return p[i];
}
return s;
}
ll wk() {
ll a=read(),b=read();
if(a>b) swap(a,b);
if(a==1) return b*b;
if(b%a!=0) return lcm(a,b);
return b*get(b);
}
int main()
{
// freopen("B.in","r",stdin);
// freopen(".out","w",stdout);
make_prime(46342);
int T=read();
while(T--) {
cout<<wk()<<endl;
}
return 0;
}
C Training Before the Olympiad
There is an array a of size n. Masha goes first, and the players take turns. Each move is described by the following sequence of actions:
If the size of the array is 1, the game ends.
he player who is currently playing chooses two different indices i, j (1≤i,j≤|a|), and performs the following operation — removes ai and aj from the array and adds to the array a number equal to ⌊ai+aj2⌋⋅2. In other words, first divides the sum of the numbers ai, aj by 2 rounding down, and then multiplies the result by 2.
Masha aims to maximize the final number, while Olya aims to minimize it. Masha and Olya decided to play on each non-empty prefix of the initial array a, and asked for your help.
For each k=1,2,…,n, answer the following question. Let only the first k elements of the array a be present in the game, with indices 1,2,…,k respectively. What number will remain at the end with optimal play by both players?
Masha一定是优先选,奇偶不同
Olya则是优先选2奇数
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
#define MAXN (100000+10)
ll a[MAXN]={},an[MAXN]={};
int main()
{
// freopen("C.in","r",stdin);
// freopen(".out","w",stdout);
int T=read();
while(T--) {
int n=read();
For(i,n) {
a[i]=read();
}
int jn=0;
ll ans=0;
For(i,n) {
if(a[i]%2) jn++;
ans+=a[i];
an[i]=ans;
if(i==1 && jn==1) continue;
if(jn>=3) {
an[i]-=jn/3;
if(jn%3==1) an[i]--;
}
else if(jn==1) an[i]--;
}
PRi(an,n)
}
return 0;
}
D
The mathematicians of the 31st lyceum were given the following task:
You are given an odd number n, and you need to find n different numbers that are squares of integers. But it’s not that simple. Each number should have a length of n (and should not have leading zeros), and the multiset of digits of all the numbers should be the same. For example, for 234 and 432, and 11223 and 32211, the multisets of digits are the same, but for 123 and 112233, they are not.
961
,
90601
,
9006001
961,90601,9006001
961,90601,9006001等数一定是squares of integers.
n
=
3
n=3
n=3时,
169
,
196
,
961
169,196,961
169,196,961是合法解。
构造出
n
=
k
−
2
n=k-2
n=k−2时,只要所有数*100,能得到
n
−
2
n-2
n−2个长度为
n
n
n的解,且末尾为2个0。
从
n
=
3
n=3
n=3的特殊解开始,每次把上一个解末尾填2个0,再加上
"
1
"
+
(
n
−
3
)
/
2
∗
"
0
"
+
"
6
"
+
(
n
−
3
)
/
2
∗
"
0
"
+
"
9
"
"1"+(n-3)/2*"0"+"6"+(n-3)/2*"0"+"9"
"1"+(n−3)/2∗"0"+"6"+(n−3)/2∗"0"+"9",
"
9
"
+
(
n
−
3
)
/
2
∗
"
0
"
+
"
6
"
+
(
n
−
3
)
/
2
∗
"
0
"
+
"
1
"
"9"+(n-3)/2*"0"+"6"+(n-3)/2*"0"+"1"
"9"+(n−3)/2∗"0"+"6"+(n−3)/2∗"0"+"1"
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
string s[105][105];
void pr(){
s[1][1]="1";
s[3][1]="169";
s[3][2]="196";
s[3][3]="961";
for(int i=5;i<=99;i+=2) {
For(j,i-2) {
s[i][j]=s[i-2][j]+"00";
}
s[i][i-1]="1"+string((i-3)/2,'0')+"6"+string((i-3)/2,'0')+"9";
s[i][i]="9"+string((i-3)/2,'0')+"6"+string((i-3)/2,'0')+"1";
}
}
int main()
{
// freopen("D.in","r",stdin);
// freopen(".out","w",stdout);
int T=read();
pr();
while(T--) {
int p=read();
For(i,p) {
cout<<s[p][i]<<endl;
}
}
return 0;
}