The decimal number, 585 = 10010010012(binary), is palindromic in both bases.

Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.

(Please note that the palindromic number, in either base, may not include leading zeros.)

题目大意:

十进制数字585 = 10010010012 (二进制),可以看出在十进制和二进制下都是回文(从左向右读和从右向左读都一样)。

求100万以下所有在十进制和二进制下都是回文的数字之和。

(注意在两种进制下的数字都不包括最前面的0)

//(Problem 36)Double-base palindromes
// Completed on Thu, 31 Oct 2013, 13:12
// Language: C
//
// 版权所有(C)acutus (mail: acutus@126.com)
// 博客地址:http://www.cnblogs.com/acutus/
#include<stdio.h>
#include<stdbool.h> bool test(int *a, int n)
{
bool flag = true;
for(int i = ; i < n/; i++) {
if(a[i] != a[n-i-]) {
flag = false;
break;
}
}
return flag;
} bool palindromes(int n, int base) //判断整数n在基为base时是否为回文数
{
int a[];
int i = ;
while(n) {
a[i++] = n % base;
n /= base;
}
return test(a,i);
} int main(void)
{
int sum = ;
for(int i = ; i <= ; i += )
{
if(palindromes(i, ) && palindromes(i, ))
sum += i;
}
printf("%d\n", sum);
return ;
}
Answer:
872187

(Problem 36)Double-base palindromes的更多相关文章

  1. (Problem 42)Coded triangle numbers

    The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangl ...

  2. (Problem 70)Totient permutation

    Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...

  3. (Problem 29)Distinct powers

    Consider all integer combinations ofabfor 2a5 and 2b5: 22=4, 23=8, 24=16, 25=32 32=9, 33=27, 34=81, ...

  4. (Problem 73)Counting fractions in a range

    Consider the fraction, n/d, where n and d are positive integers. If nd and HCF(n,d)=1, it is called ...

  5. (Problem 41)Pandigital prime

    We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly o ...

  6. (Problem 74)Digit factorial chains

    The number 145 is well known for the property that the sum of the factorial of its digits is equal t ...

  7. (Problem 46)Goldbach's other conjecture

    It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a ...

  8. (Problem 72)Counting fractions

    Consider the fraction, n/d, where n and d are positive integers. If nd and HCF(n,d)=1, it is called ...

  9. (Problem 53)Combinatoric selections

    There are exactly ten ways of selecting three from five, 12345: 123, 124, 125, 134, 135, 145, 234, 2 ...

随机推荐

  1. Checking Network Configuration requirements Failed

    安装oracle执行检查,出现 Checking Network Configuration requirements ... Check complete. The overall result o ...

  2. Thread’s start method and run method

    工作中用到了Thread,一开始用错了,仔细研究了一下,稍作整理. 前言,今天写代码居然这样写的 new Thread() { @Override public void run() { System ...

  3. ASP.NET快速开发框架、这才是高大上档次后台管理UI界面

    另外献上在<线体验Demo地址>希望大家也能从中得到一些启发.地址:http://121.40.148.178:8080/ . 用户名:guest,密码:123456QQ技术交流群:239 ...

  4. final, finally, finalize 的区别

    1.final 用于声明属性, 方法和类, 分别表示属性不可变, 方法不可覆盖, 类不可继承.内部类要访问局部变量, 局部变量必须定义成 final 类型, 例如, 一段代码…… 2.finally ...

  5. PHP获取网址的PR值

    PR值是google衡量网站的重要标准之一,根据google提供的结果获取pr值,如:http://toolbarqueries.google.com.hk/tbr?client=navclient- ...

  6. 创建理想的SEQUENCE和自增长的trigger

    SEQUENCE CREATE SEQUENCE TEST_SEQ START 1 --从1开始,第一个一定是NEXTVAL,因为第一个CURRVAL不好使,返回值会是1,第一个NEXTVAL相当于从 ...

  7. widget intent重复问题

    今天在做android widget时发现点击任意widget时只会更新最后一个widget 原来是requestCode的问题 Intent intent = new Intent(WidgetPr ...

  8. Output in PowerShell

    Reference article: https://rkeithhill.wordpress.com/2007/09/16/effective-powershell-item-7-understan ...

  9. 帝国cms7.2自定义列表建立tag效果 代码 教程

    统计记录:(如:select count(*) as total from phome_ecms_news where classid=1 and checked=1) 注:这句SQL的意思是查找统计 ...

  10. 26_Json_Example

    JSON 很通用的处理数据的工具,各个语言都可以使用. 这个App就是把一个网上的用JSON格式保存的数据拿下来,然后保存到字典中,显示出来,用iOS自己的方法. 一定要记得写最后的那个 task.r ...