Sakura4869 @ 2022-09-12 21:05:05
为什么它除了第一次都会先把b+1再相乘呢???
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 5;
int a[MAXN],b[MAXN],c[MAXN];
int t[MAXN];
void read(int a,int x[]){
int tmp = a,d = 0;
while(tmp > 0){
d++;
x[d] = tmp % 10;
tmp /= 10;
}
x[0] = d;
}
void print(int x[]){
for(int i = x[0];i >= 1;i--)printf("%d",x[i]);
//printf("\n");
}
void besame(int x[],int y[]){
for(int i = y[0];i >= 0;i--)y[i] = 0;
for(int i = 0;i <= x[0];i++)y[i] = x[i];
}
void mul(int x[],int y[],int z[]){
z[0] = max(x[0],y[0]);
for(int i = 1;i <= x[0];i++){
for(int j = 1;j <= y[0];j++){
z[i + j - 1] += x[i] * y[j];
}
}
for(int i = 2;i <= x[0] + y[0] + 2;i++){
z[i] += z[i - 1] / 10;
z[i - 1] %= 10;
if(z[z[0] + 1] > 0)z[0]++;
if(z[z[0]] == 0 && z[0] != 1)z[0]--;
}
}
int main(){
int n;
scanf("%d",&n);
int cnt = 0,tmp = n;
for(int i = 2;i <= n;i++){
if(i <= tmp){
cnt++;
t[cnt] = i;
tmp -= i;
}
}
int tcnt = cnt;
while(tmp > 0){
t[tcnt]++;
tmp--;
tcnt = (tcnt - 2 + n) % n + 1;
}
a[0] = 1,a[1] = 1;
for(int i = 1;i <= cnt;i++){
//printf("%d\n",t[i]);
read(t[i],b);
printf("");
print(b);
printf(" * ");
print(a);
mul(b,a,c);
printf(" = ");
print(c);
printf("\n");
besame(c,a);
}
print(a);
return 0;
}