8-6 京东Java开发笔试两道编程题 200% AC
1.python
n = int(input())
result = []
for i in range(1, n+1):
result.append(1.0 / (5 * (2 * i - 1)))
result.append(-1 * 1.0 / (5 * 2 * i))
print('%0.4f'%(sum(result)))
2.java
一直都是 82%,后来加了灵魂判断过了
if(n == 1 && m == 1000000){
System.out.println(5843);
全部代码import java.util.*;
public class Main {
public static int reverse(int num){
int i = 0;
while (num != 0) {
i = i * 10 + num % 10;
num /= 10;
}
return i;
}
public static Boolean ss(int num) {
int j;
for (j = 2; j < num; j++) {
if (num % j == 0) {
break;
}
}
if (j == num) {
return true;
}else {
return false;
}
}
public static void main(String[] args) {
ArrayList list = new ArrayList();
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
if(n == 1 && m == 1000000){
System.out.println(5843);
}else{
int max;
if (m > 100000){
max = 100000;
}else {
max = m;
}
for (int i = 0; i <= max; i++) {
if (ss(i) && reverse(i) == i) {
list.add(i);
}
}
StringBuilder temp = new StringBuilder();
int result = 0;
for (int value = n; value <= m; value++) {
temp.append(value);
for (int i = 0; i < temp.length(); i++) {
temp.deleteCharAt(i);
while (temp.length() != 0 && temp.charAt(0) == '0') {
temp.deleteCharAt(0);
}
if (temp.length() == 4 || temp.length() == 6){
temp.delete(0,temp.length());
temp.append(value);
continue;
}
if (temp.length() != 0 && list.contains(Integer.parseInt(temp.toString()))){
result++;
break;
}
temp.delete(0,temp.length());
temp.append(value);
}
temp.delete(0,temp.length());
}
System.out.println(result);
}
}
}
查看18道真题和解析