fork download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4. int cha[15];
  5. int lis[15];
  6. int selection[10005],k = 0;
  7. int n;
  8. bool check(){
  9. bool kq = false;
  10. for (int i = 0 ; i <= 9 ; i++){
  11. if(cha[i]!=0)return false;
  12. }
  13. return true;
  14. }
  15. vector<int> kq;
  16. bool timthay = false;
  17. void dequy(int vitri , int now , vector<int> v){
  18. if(timthay)return;
  19. if(now == n && check()){
  20. kq = v;
  21. timthay = true;
  22. return;
  23. }
  24. if(vitri == k || now > n)return;
  25. // chon selection hientai
  26. if (n % (now * selection[vitri]) == 0){
  27. string s1=to_string(selection[vitri]);
  28. bool khathi = true;
  29. for (char x : s1){
  30. cha[x-'0']--;
  31. if(cha[x-'0']<0)khathi=false;
  32. }
  33. if(khathi){
  34. v.push_back(selection[vitri]);
  35. dequy(vitri,now*selection[vitri],v);
  36. v.pop_back();
  37. }
  38. //khoi phuc
  39. for (char x : s1){
  40. cha[x-'0']++;
  41. }
  42. }
  43.  
  44. //ko chon
  45. dequy(vitri+1,now,v);
  46. }
  47. vector<int> temp;
  48. signed main() {
  49. ios_base::sync_with_stdio(false);
  50. cin.tie(NULL);
  51. cin >> n;
  52. string s;
  53. cin>>s;
  54. for (char x : s){
  55. cha[x-'0']++;
  56. }
  57. set<int> liset;
  58. for (int i = 1 ; i*i <= n ; i++){
  59. if(n%i==0){
  60. for (int j = 0 ; j <= 9 ; j++)lis[j]=0;
  61. string s1 = to_string(n/i);
  62. for (char x : s1)lis[x-'0']++;
  63. bool check1 =true;
  64. for (int j = 0 ; j <= 9 ; j++){
  65. if(lis[j]>cha[j]){
  66. check1=false;
  67. break;
  68. }
  69. }
  70. for (int j = 0 ; j <= 9 ; j++)lis[j]=0;
  71. string s2 = to_string(i);
  72. for (char x : s2)lis[x-'0']++;
  73. bool check2 =true;
  74. for (int j = 0 ; j <= 9 ; j++){
  75. if(lis[j]>cha[j]){
  76. check2=false;
  77. break;
  78. }
  79. }
  80. //cout<<i<<" "<<n/i<<"\n";
  81. if(check1)liset.insert(n/i);
  82. if(check2)liset.insert(i);
  83. }
  84. }
  85. for (auto x : liset)selection[k++]=x;
  86. dequy(0,1,temp);
  87. cout<<kq.size()<<" ";
  88. for (auto x : kq)cout<<x<<" ";
  89. return 0;
  90. }
Success #stdin #stdout 0.1s 5312KB
stdin
735134400
73513440099999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
stdout
0