(Problem 36)Double-base palindromes
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的更多相关文章
- (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 ...
- (Problem 70)Totient permutation
Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...
- (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, ...
- (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 ...
- (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 ...
- (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 ...
- (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 ...
- (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 ...
- (Problem 53)Combinatoric selections
There are exactly ten ways of selecting three from five, 12345: 123, 124, 125, 134, 135, 145, 234, 2 ...
随机推荐
- Codeforces Round #242 (Div. 2) <A-D>
CF424 A. Squats 题目意思: 有n(n为偶数)个x和X,求最少的变换次数,使得X的个数为n/2,输出变换后的序列. 解题思路: 统计X的个数ans,和n/2比較,少了的话,须要把n/2- ...
- .Net MVC 入门之Razor语法
Razor语法 Razor是以后MVC项目中都需要用的, 所以在学MVC的基础的时候,我们的目标:要了解熟悉Razor页面的语法结构,做到灵活使用,so我们马上开始学习Razor,也请你们多评论和推荐 ...
- C++中 指针 与 引用 的区别
四点区别:可否为空,可否修改,使用时是否需要判断,使用场景 非空区别. 引用必须指向某个对象,而指针可以指向空. 可修改区别. 引用总是与初始化时的那个对象绑定,不可变更:指针可以重新赋值,指向另外一 ...
- #ifndef 与 #program once 的区别(转)
转自http://hi.baidu.com/hrx20091001/item/ee70f7cc6d036d4ea9ba94e0 #ifndef 与 #program once 的区别 为了避免同一个文 ...
- python --appium搭建环境过程 ---新手总结(大牛勿喷,新手互相交流)
首先安装python 安装包:https://yunpan.cn/cSdYZqjJ4xDZ3 访问密码 4bf9 1.安装pip cd 到pip安装包 python setup.py inst ...
- OutputDebugString 输出信息到调试器
#include <Windows.h>#include <stdio.h>#include <stdarg.h> void __cdecl odprintf(co ...
- 转:基于node的web开发框架Express入门
JavaScript 标准参考教程(alpha) 草稿二:Node.js Express框架 GitHub TOP Express框架 来自<JavaScript 标准参考教程(alpha)&g ...
- Protel 99SE铺铜问题总结
一.PCB电路板放置铺铜有什么作用? 散热: 屏蔽 抗干扰 pcb板子带有寄生电容: 提高板子强度: 美观: 增加被抄板的难度,尤其是覆铜+黑油. 二.PROTEL不规则铺铜的方法: 1.先要知道 ...
- Azure 网站的新增功能:可配置的环境变量
编辑人员注释:本文章由 WindowsAzure 网站团队的项目经理Erez Benari撰写. Azure最常用的强大功能之一是 XML文档转换 (XDT),通过此功能,您可以在Windows ...
- HDU 1000 A + B Problem
#include int main() { int a,b; while(scanf("%d%d",&a,&b)!=EOF) printf("%d\n&q ...