1 条题解
-
0
C :
#include<stdio.h> int ishw(int n){ int m=0,t,k=n; while(k!=0){ t=k%10; m=m*10+t; k=k/10; } if(m==n){ return 1; }else{ return 0; } } int iszs(int n){ int i; if(n<2){ return 0; } for(i=2;i<=n-1;i++){ if(n%i==0){ return 0; } } return 1; } int main() { int i; for(i=10;i<=1000;i++){ if(ishw(i)==1&&iszs(i)==1){ printf("%d\n",i); } } return 0; }C++ :
#include <cstdlib> #include <sstream> #include <string> #include <iostream> int main() { for (size_t ii = 11; ii < 1000;++ii) { std::stringstream sstemp; sstemp << ii; std::string str1, str2; sstemp >> str1; str2.assign(str1.rbegin(),str1.rend()); if (str1==str2) { for (size_t jj = 2; jj < ii;++jj) { if (ii%jj) { if (jj == ii - 1) { std::cout << ii << std::endl; } } else { break; } } } } system("pause"); return EXIT_SUCCESS; }Java :
public class Main { public static void main(String[] args) { for(int i=10;i<=1000;i++){ if(isHws(i)&&isZs(i)){ System.out.println(i); } } } public static boolean isHws(int n){ boolean f=true; char[] charArray=String.valueOf(n).toCharArray(); for(int i=0;i<charArray.length;i++){ if(charArray[i]!=charArray[charArray.length-i-1]&&i!=charArray.length-i-1){ f=false;break; } } return f; } public static boolean isZs(int n){ boolean f=true; int count=0; for(int i=1;i<=n;i++){ if(n%i==0&&i!=1&&i!=n){ count++; } } if(count>0){ f=false; }else{ f=true; } return f; } }Python :
import math def suShu(n): f = True for i in range (2 , int(math.sqrt(n))+1): if n % i == 0: f = False break; return f and n != 1 def hwsuShu(n): a = n // 100 % 10 b = n // 10 % 10 c = n % 10 if n < 100: return b == c and suShu(n); elif n > 100: return a == c and suShu(n); else: return False for i in range (10, 1000): if hwsuShu(i): print(i)
- 1
信息
- ID
- 137
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 10
- 标签
- 递交数
- 4
- 已通过
- 3
- 上传者