fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. bool SNT(int n) {
  6. if (n < 2) return false;
  7. for (int i = 2; i <= sqrt(n); i++) {
  8. if (n % i == 0) return false;
  9. }
  10. return true;
  11. }
  12.  
  13.  
  14. void PhanTichNT(int n) {
  15. cout << n << " = ";
  16. bool first = true;
  17. for (int i = 2; i <= sqrt(n); i++) {
  18. while (n % i == 0) {
  19. if (!first) cout << " * ";
  20. cout << i;
  21. first = false;
  22. n /= i;
  23. }
  24. }
  25. if (n > 1) {
  26. if (!first) cout << " * ";
  27. cout << n;
  28. }
  29. cout << endl;
  30. }
  31.  
  32.  
  33. void LietKeNT(int n, int s) {
  34. int start = pow(10, n - 1);
  35. int end = pow(10, n) - 1;
  36.  
  37. for (int i = start; i <= end; i++) {
  38. if (SNT(i)) {
  39. int tmp = i, tong = 0;
  40. while (tmp > 0) {
  41. tong += tmp % 10;
  42. tmp /= 10;
  43. }
  44. if (tong == s) {
  45. cout << i << " ";
  46. }
  47. }
  48. }
  49. cout << endl;
  50. }
  51.  
  52.  
  53. int main(){
  54. //1.Input
  55. int n; cin>>n;
  56. int choice; cin>>choice;
  57. //2.Process
  58. if(choice==1){
  59. PhanTichNT(n);
  60. }else{
  61. int s; cin>>s;
  62. LietKeNT(n,s);
  63. }
  64. //3.Output
  65. return 0;
  66. }
  67.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout