Project Euler:Problem 63 Powerful digit counts
The 5-digit number, 16807=75, is also a fifth power. Similarly, the 9-digit number, 134217728=89, is a ninth power.
How many n-digit positive integers exist which are also an nth power?
这种数字满足下面条件:
对于数位为x的数S=k^x 有 10^(x-1)<=k^x<=10^x-1
#include "stdafx.h"
#include <iostream>
using namespace std; int main()
{
int count = 0;
for (int i = 1; i < 100; i++)
{
double n = pow(10, 1.0 - 1.0 / i);
int tmp = int(n);
if (n - tmp>0.0)
tmp++;
if (tmp > 9)
break; count += 9 - tmp + 1;
//cout << n << " " << tmp << endl;
}
cout << count << endl;
system("pause");
return 0;
}
Project Euler:Problem 63 Powerful digit counts的更多相关文章
- Project Euler 63: Powerful digit counts
五位数\(16807=7^5\)也是一个五次幂,同样的,九位数\(134217728=8^9\)也是一个九次幂.求有多少个\(n\)位正整数同时也是\(n\)次幂? 分析:设题目要求的幂的底为\(n\ ...
- Project Euler:Problem 34 Digit factorials
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. Find the sum of all numbers which are ...
- Project Euler:Problem 33 Digit cancelling fractions
The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplif ...
- Project Euler:Problem 55 Lychrel numbers
If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindr ...
- Project Euler:Problem 32 Pandigital products
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly o ...
- Project Euler:Problem 86 Cuboid route
A spider, S, sits in one corner of a cuboid room, measuring 6 by 5 by 3, and a fly, F, sits in the o ...
- Project Euler:Problem 76 Counting summations
It is possible to write five as a sum in exactly six different ways: 4 + 1 3 + 2 3 + 1 + 1 2 + 2 + 1 ...
- Project Euler:Problem 87 Prime power triples
The smallest number expressible as the sum of a prime square, prime cube, and prime fourth power is ...
- Project Euler:Problem 89 Roman numerals
For a number written in Roman numerals to be considered valid there are basic rules which must be fo ...
随机推荐
- Mysql添加和删除唯一索引、主键
1.PRIMARY KEY(主键索引) 添加 ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` );删除 ALTER TABLE `table_n ...
- ViewPager的简单用法+适配器+监听器的介绍
之前的actionbar+fragment文章中写过viewpager的简单用法,但因为是融合的文章,所以今天把viewpager提取出来写了.方便查询浏览~ 思路: 1.在布局文件中设置viewpa ...
- Eclipse with ADT的安装和配置
我们从安卓官方网站(https://developer.android.com/sdk/index.html#download)下载下来的eclipse是捆绑好了ADT的,所以不用自己安装插件,十分方 ...
- [转]PHP用mysql数据库存储session
From : http://www.php100.com/html/webkaifa/PHP/PHPyingyong/2010/0226/4002.html 大部分使用php的人一旦应用到sessio ...
- 【转】Delphi"配置系统未能初始化"
好久没用DelphiXE8了,最近打开一看,在启动时报错了“配置系统未能初始化”,在网上一搜,有各种种样的说法,大体上是与.net的Framewok相关,照着一个一个地试了下,还是解决不了这个错误.有 ...
- iOS开发-UILabel和UIButton添加下划线
关于UILabel和UIButton有的时候需要添加下划线,一般有两种方式通过默认的NSMutableAttributedString设置,第二种就是在drawRect中画一条下划线,本文就简单的选择 ...
- Wildcard Matching leetcode java
题目: Implement wildcard pattern matching with support for '?' and '*'. '?' Matches any single charact ...
- 整合spring cloud云架构 - SSO单点登录之OAuth2.0登录认证(1)
之前写了很多关于spring cloud的文章,今天我们对OAuth2.0的整合方式做一下笔记,首先我从网上找了一些关于OAuth2.0的一些基础知识点,帮助大家回顾一下知识点: 一.oauth中的角 ...
- 用css3和jQuery制作精美的表单
用css3和jQuery制作一个简单的精美表单 html代码如下: <span class="title">Mask Your Input Forms and Make ...
- qt文字改变方向
QPainter painter(this); QFont font("Courier", 24); painter.setFont ...