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. HDU 5446 Unknown Treasure(Lucas定理+CRT)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5446 [题目大意] 给出一个合数M的每一个质因子,同时给出n,m,求C(n,m)%M. [题解] ...

  2. Mysql文件太大导入失败解决办法总结

    Mysql文件太大导入失败解决办法总结 在使用phpmyadmin导入数据库的时候可能会碰到由于数据库文件太大而无法导入的问题! 英文提示如下:File exceeds the maximum all ...

  3. c#中常用的异常类型

    c#中异常捕获catch{}常用的异常类型 Exception 类   描述 SystemException 其他用户可处理的异常的基本类  ArgumentException 方法的参数是非法的  ...

  4. 三分钟教你学Git(十六) - 统计

    有时候想统计仓库的情况,比方代码量.贡献者之类的. 1 统计某人的commit数量 git log --author="$(git config --get user.name)" ...

  5. javascript数字验证输入

    javascript数字验证功能: <html> <body> <p>请输入数字.如果输入值不是数字,浏览器会弹出提示框.</p> <input ...

  6. iOS面试题02-数据存储

    1.如果后期需要增加数据库中的字段怎么实现,如果不使用CoreData呢? 回答:编写SQL语句来操作原来表中的字段 1>增加表字段 ALETER TABLE 表名 ADD COLUMN 字段名 ...

  7. hdu 2519 新生晚会 排列组合

    通过阶段性计算减少一次性的大值计算 #include <stdio.h> int main() { int t, a, b, i; __int64 c; scanf("%d&qu ...

  8. Java反射的小故事

    Java反射的小故事: 首先定义一个Java类 package com.xiaoysec.test; public class Person { private String name; privat ...

  9. BZOJ 2329: [HNOI2011]括号修复( splay )

    把括号序列后一定是))))((((这种形式的..所以维护一个最大前缀和l, 最大后缀和r就可以了..答案就是(l+1)/2+(r+1)/2...用splay维护,O(NlogN). 其实还是挺好写的, ...

  10. (转)WIN2003服务器禁PING的方法

    方法一:用windows系统自带的防火墙规则设置禁止别人Ping我的机器 win2003系统默认情况下,所有Internet控制消息协议(ICMP)选项均被禁用,也就是对客户机有反应,因而易于受到攻击 ...