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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
#include <iostream> #include <stdio.h> #include <map> #include <vector> using namespace std; map<int,int> m,n; vector<int> den[80]; vector<int> numer[80]; int main() { int cnt,org; for(int i=0;i<80;i++) { den[i].clear(); numer[i].clear(); } for(int i=1234;i<=98765;i++) { if(i%10==0 && i<10000) continue; org=i; m.clear(); if(i<10000) m[0]=1; while(org) { if(m[org%10]) break; m[org%10]=1; org/=10; } if(org) continue; cnt=1; for(int j=i*2;j<100000;j+=i) { cnt++; if(i<10000 && j<10000) continue; org=j; n.clear(); while(org) { if(m[org%10]==1 || n[org%10]==1) break; n[org%10]=1; org/=10; } if(org) continue; if(i<10000 && n[0]==1) continue; numer[cnt].push_back(j); den[cnt].push_back(i); } } int N,c=0; while(cin>>N) { if(N==0) break; if(c) cout<<"\n"; c=1; if(den[N].size()==0) cout<<"There are no solutions for "<<N<<".\n"; else { //cout<<den[N].size()<<"\n"; for(int i=0;i<den[N].size();i++) { if(numer[N][i]<10000) cout<<0; cout<<numer[N][i]; cout<<" / "; if(den[N][i]<10000) cout<<0; cout<<den[N][i]<<" = "<<N<<"\n"; } } //cout<<"\n"; } return 0; } |