圆环上求素数III

This commit is contained in:
James 2020-06-13 10:02:37 +08:00
parent 6e418781f6
commit f457f39977
10 changed files with 111 additions and 1 deletions

View File

@ -24,7 +24,8 @@
"vector": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"string_view": "cpp"
"string_view": "cpp",
"cmath": "cpp"
},
"terminal.integrated.automationShell.windows": "cmd.exe",
"files.encoding": "gb18030",

View File

@ -0,0 +1,3 @@
# 标题
* 内容

View File

@ -0,0 +1 @@
#

Binary file not shown.

View File

@ -0,0 +1,81 @@
#include <cmath>
#include <iostream>
using namespace std;
int n, k,a[8] = { 0, 1, 2, 3, 4, 5, 6, 7 },allans=0;
bool ce[8]={0};
bool pan(int n)
{
int len = sqrt(n);
for (int i = 2; i <= len; i++) {
if (n % i == 0) {
return 0;
}
}
return 1;
}
void dg(int xian){
if(xian>n){
// for(int i=1;i<=n;i++){
// cout<<a[i]<<" ";
// }
// cout<<endl;
int now = 0, zong = 1, ans = 0;
for (int i = n - k + 2; i <= n; i++) {
now *= 10;
now += a[i];
zong *= 10;
}
for (int i = 1; i <= n; i++) {
now %= zong;
now *= 10;
now += a[i];
ans += pan(now);
}
if(ans>allans){
allans=ans;
}
}
for(int i=2;i<=n;i++){
if(ce[i]==0){
a[xian]=i;
ce[i]=1;
dg(xian+1);
ce[i]=0;
}
}
}
int main()
{
int now = 0, zong = 1, ans = 0;
cin >> n >> k;
if (k == 1) {
if (n == 1) {
cout << "0" << endl
<< "0";
} else {
int chu = 1;
for (int i = 3; i <= n; i+=2) {
chu++;
}
cout << chu << endl
<< chu;
}
} else {
for (int i = n - k + 2; i <= n; i++) {
now *= 10;
now += a[i];
zong *= 10;
}
for (int i = 1; i <= n; i++) {
now %= zong;
now *= 10;
now += a[i];
ans += pan(now);
}
cout<<ans<<endl;
dg(2);
cout<<allans;
}
return 0;
}

Binary file not shown.

View File

@ -0,0 +1 @@
7 1

View File

@ -0,0 +1 @@
7 3

View File

@ -0,0 +1 @@
6 4

View File

@ -0,0 +1,21 @@
## z:\Chao\src\1598_roundfind_sushu\test\in.txt
2020/06/13 ÖÜÁù 9:56:47.43
4
4
-----------------------------------------------
Process exited after 180 ms with return value 0
## z:\Chao\src\1598_roundfind_sushu\test\in2.txt
2020/06/13 ÖÜÁù 9:56:47.43
0
3
-----------------------------------------------
Process exited after 100 ms with return value 0
## z:\Chao\src\1598_roundfind_sushu\test\in3.txt
2020/06/13 ÖÜÁù 9:56:47.43
1
2
-----------------------------------------------
Process exited after 90 ms with return value 0