1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
| #include<queue>
#include<stack>
#include<vector>
#include<iostream>
using namespace std;
typedef long long ll;
struct Comb{
int N,x,y;
};
constexpr ll pow10[20]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000,100000000000,1000000000000,10000000000000,100000000000000,1000000000000000,10000000000000000,100000000000000000,1000000000000000000,10000000000000000000};
bool check(int N,ll x,ll y){
for(int i=0;i<=N;i++)
if( (x/pow10[i]%10) * (y/pow10[i]%10) != ((x*y)/pow10[2*i]%100) ) return false;
if( x/pow10[N+1] != (x*y)/pow10[2*N+2] ) return false;
return true;
}
stack<Comb> q;
int main(){
for(int i=1;i<=9;i++) for(int j=1;j<=9;j++) q.push({0,i,j});
while(!q.empty()){
Comb u = q.top(); q.pop();
int N = u.N;ll x = u.x, y = u.y;
if(N==8) continue;
if(N&1) if((x/pow10[N/2]%10)*(y/pow10[N/2]%10)!=((x*y)/pow10[N-1]%100)) continue;
if(N) for(int i=1;i<10;i++) if(check(N,i*pow10[N+1]+x,y)){
cout<<i*pow10[N+1]+x<<'*'<<y<<'='<<(i*pow10[N+1]+x)*y<<endl;
}
for(int i=1;i<10;i++) for(int j=1;j<10;j++)
q.push({N+1,(int)(i*pow10[N+1]+x),(int)(j*pow10[N+1]+y)});
}
return 0;
}
|