整数拆段

This commit is contained in:
James 2020-03-28 08:36:16 +08:00
parent 83fac884dc
commit 4dc41586f5
9 changed files with 76 additions and 0 deletions

25
1653_numcutup/Readme.md Normal file
View File

@ -0,0 +1,25 @@
# 整数拆段
[问题描述]
教学案例,必须使用函数完成求解!
  将一个长度小于15位的数字串拆成2段使其和为最小的素数。
  例如数字串13304拆的方法有:
   1 + 3304 = 3305
   13 + 304 = 317
   133 + 04 = 137
   1330 + 4 = 1334
  从上面可看出和为素数的有317 与137最小的是137
[输入格式]
  一个长度小于15的数字串。
[输出格式]
  最小的和为素数的数,若无素数则输出 -1。
[输入样例]
13304
[输出样例]
137

View File

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

6
1653_numcutup/main.cpp Normal file
View File

@ -0,0 +1,6 @@
#include <iostream>
int main()
{
std::cout << "Hello Easy C++ project!" << std::endl;
}

BIN
1653_numcutup/main.exe Normal file

Binary file not shown.

View File

@ -0,0 +1,28 @@
#include<iostream>
using namespace std;
bool pan(long long n){
if(n<2){
return 0;
}
for(int i=2;i*i<=n;i++){
if(n%i==0){
return 0;
}
}
return 1;
}
int main(){
long long n,a=10,b,ans=1000000000000000;
cin>>n;
for(int i=10;a>=10;i*=10){
a=n/i;
b=n%i;
if(a+b<ans&&pan(a+b)==1){
ans=a+b;
}
}
if(ans==1000000000000000){
ans=-1;
}
cout<<ans;
}

BIN
1653_numcutup/numcutup.exe Normal file

Binary file not shown.

View File

@ -0,0 +1 @@
13304

View File

@ -0,0 +1 @@
33

View File

@ -0,0 +1,12 @@
## z:\Chao\src\1653_numcutup\test\in.txt
2020/03/27 ÖÜÎå 17:59:38.77
137
-----------------------------------------------
Process exited after 160 ms with return value 0
## z:\Chao\src\1653_numcutup\test\in2.txt
2020/03/27 ÖÜÎå 17:59:38.77
-1
-----------------------------------------------
Process exited after 90 ms with return value 0