shusu1669 『入门』(递归专题)m位数问题

This commit is contained in:
James 2020-04-30 18:40:13 +08:00
parent 777981363e
commit ef43e42fd4
8 changed files with 80 additions and 0 deletions

17
1669_nweishu/Readme.md Normal file
View File

@ -0,0 +1,17 @@
# 1669 『入门』递归专题m位数问题
[问题描述]
  考官只给两个整数n和m1 <= n <= 81 <= m <= 5要求选手从1,2,…,n中取出m个数字组成一个m位整数统计所有的m位整数中一共有多少个素数。
  如n=3,m=2时符合条件的整数有11 12 13 21 22 23 31 32 33。其中素数有11 13 23 31一共有4个。
[输入格式]
  一行两个整数n m1 <= n <= 81 <= m <= 5 )。
[输出格式]
  一行,一个整数,表示素数的个数。  
[输入样例]
3 2
[输出样例]
4

View File

@ -0,0 +1 @@
#

41
1669_nweishu/main.cpp Normal file
View File

@ -0,0 +1,41 @@
#include <iostream>
#include <cmath>
using namespace std;
int shu,chang,flag=0,ans=0;
bool pan(int n){
if(n<2){
return 0;
}
if(n==2){
return 1;
}
int len=sqrt(n);
for(int i=2;i<=len;i++){
if(n%i==0){
return 0;
}
}
return 1;
}
void dg(int now){
if(now==chang+1){
if(pan(flag)==1){
ans++;
}
}else{
for(int i=1;i<=shu;i++){
flag*=10;
flag+=i;
dg(now+1);
flag/=10;
}
}
}
int main()
{
cin>>shu>>chang;
dg(1);
cout<<ans;
}

BIN
1669_nweishu/main.exe Normal file

Binary file not shown.

1
1669_nweishu/test/in.txt Normal file
View File

@ -0,0 +1 @@
8 4

View File

@ -0,0 +1 @@
8 5

View File

@ -0,0 +1 @@
8 1

18
1669_nweishu/test/out.txt Normal file
View File

@ -0,0 +1,18 @@
## z:\Chao\src\1669_nweishu\test\in.txt
2020/04/30 ÖÜËÄ 18:38:22.64
464
-----------------------------------------------
Process exited after 150 ms with return value 0
## z:\Chao\src\1669_nweishu\test\in2.txt
2020/04/30 ÖÜËÄ 18:38:22.64
2871
-----------------------------------------------
Process exited after 140 ms with return value 0
## z:\Chao\src\1669_nweishu\test\in3.txt
2020/04/30 ÖÜËÄ 18:38:22.64
4
-----------------------------------------------
Process exited after 100 ms with return value 0