Li_mz__ @ 2022-09-16 21:46:44
#include <bits/stdc++.h>
using namespace std;
int main(){
string s1,s2;
long long x[1005] = {0},y[1005] = {0},sum[2005] = {0};
cin>>s1>>s2;
long long l1 = s1.length();
long long l2 = s2.length();
for(long long i = 0;i < l1;i++){
x[l1 - 1 - i] = s1[i] - '0';
}
for(long long i = 0;i < l2;i++){
y[l2 - 1 - i] = s2[i] - '0';
}
for(long long i = 0;i < l1;i++){
for(long long j = 0;j < l2;j++){
sum[i + j] += x[i] * y[j];
sum[i + j + 1] += sum[i + j] / 10;
sum[i + j] %= 10;
}
}
long long l = l1 + l2;
while(sum[l] == 0 && l != 0){
l--;
}
for(long long i = l;i >= 0;i--){
cout<<sum[i];
}
return 0;
}
求大佬看看
by Katz @ 2022-09-16 21:47:34
TLE关long long什么事啊喂(
by RP_INT_MAX @ 2022-09-16 21:48:47
@Li_mz__ long long 慢了吧。。。为什么要 long long /yiw
by Li_mz__ @ 2022-09-16 21:49:20
哦
那不开long long也不对啊
by scp020 @ 2022-09-16 21:58:23
这题不用long long的
by scp020 @ 2022-09-16 21:59:26
您看我压行压的
#include<bits/stdc++.h>
using namespace std;
int a[2010],b[2010],c[4010],len;
string s1,s2;
int main()
{
cin>>s1>>s2,len=s1.size()+s2.size();
for(int i=s1.size()-1;i>=0;i--) a[s1.size()-i]=s1[i]-'0';
for(int i=s2.size()-1;i>=0;i--) b[s2.size()-i]=s2[i]-'0';
for(int i=1;i<=s1.size();i++) for(int j=1;j<=s2.size();j++) c[i+j-1]+=a[i]*b[j];
for(int i=1;i<=len;i++) c[i+1]+=c[i]/10,c[i]%=10;
while(!c[len]) len--;
for(int i=max(len,1);i>=1;i--) cout<<c[i];
return 0;
}
by scp020 @ 2022-09-16 21:59:57
@Li_mz__ 您数组开小了
by scp020 @ 2022-09-16 22:00:29
@Li_mz__ 数组开小不一定RE,可能访问到了幽灵指针
by 654179_qwq @ 2022-09-16 22:06:29
用 FFT , 超时我负责
by Li_mz__ @ 2022-09-17 21:30:16
@654179_qwq
if(我不会)
by Li_mz__ @ 2022-09-17 21:31:00
@scp020 哦,那玩意我还没学(幽灵指针)
多谢大佬