Prime Palindromes The number 151 is a prime palindrome because it is both a prime number and a palindrome (it is the same number when read forward as backward). Write a program that finds all prime palindromes in the range of two supplied numbers a a…
Description The number 151 is a prime palindrome because it is both a prime number and a palindrome (it is the same number when read forward as backward). Write a program that finds all prime palindromes in the range of two supplied numbers a and b (…
一.题目描述 The number 151 is a prime palindrome because it is both a prime number and a palindrome (it is the same number when read forward as backward). Write a program that finds all prime palindromes in the range of two supplied numbers a and b (5 <=…
这道题目一点也不卡素数的判断 就是朴素的sqrt(n) 也不卡 所以~放心的用吧. 构造回文的时候看了HINT 其中是这么写的: Generate palindromes by combining digits properly. You might need more than one of the loops like below. /* generate five digit palindrome: */ for (d1 = 1; d1 <= 9; d1+=2) { /* only odd…
题解: 第一次: 算法复杂度过高,导致编译超时,需要优化 #include<stdio.h>#include<math.h>int a[100000001] = { 0 };int p(int n) { int t = n, ret = 0; while (t > 0) { t /= 10; ret++; } if (ret == 1) { printf("%d\n", n); return 0; } t = ret; t /= 2; ret -=…
import java.util.Scanner; public class Main { private static Scanner cin; public static void main(String args[]) throws Exception { cin = new Scanner(System.in); int a = cin.nextInt(); int b = cin.nextInt(); for (int i=a; i<=b; i++) { //如果可以被2.3.5整除,…
USACO Chapter 1 解题总结 1.1.1 Your Ride Is Here 基本字符串操作,无压力. 1.1.2 Greedy Gift Givers 基础模拟题,弄明白题意,不怕麻烦,就OK了. 1.1.3 Friday the Thirteenth 自己的做法:三维数组代表年月日,400的数据范围不大,模拟走一下时间的流逝过程即可.时间复杂度O(N*12*31),多好玩. 官方标程好像用到了一个神奇的公式,好像是什么蔡勒公式. 1.1.4 Broken Necklace 2*N…
几天时间就把USACO chapter1重新做了一遍,发现了自己以前许多的不足.蒽,现在的程序明显比以前干净很多,而且效率也提高了许多.继续努力吧,好好的提高自己.这一章主要还是基本功的训练,没多少的思维难度,不过基础也是很重要的. ——2013年11月17日 1.1.1 Your Ride Is Here 题目很简单,长字符串读入,按位相乘,同时取模即可,一开始的时候居然忘记了给d1和d2赋值1,结果无论是什么字符串读入计算结果都为0,虽然是水题,还是要记住初始化! {ID: jiangyi…