鱼C论坛

 找回密码
 立即注册
查看: 2866|回复: 7

题目119:考察可以写成各位数之和的幂的数字

[复制链接]
发表于 2016-8-21 02:40:02 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 欧拉计划 于 2016-8-22 22:37 编辑
Digit power sum

The number 512 is interesting because it is equal to the sum of its digits raised to some power: 5 + 1 + 2 = 8, and 83 = 512. Another example of a number with this property is 614656 = 284.

We shall define an to be the nth term of this sequence and insist that a number must contain at least two digits to have a sum.

You are given that a2 = 512 and a10 = 614656.

Find a30.


题目:

512 是有趣的,因为他正好等于他的各位数字之和的幂: 5 + 1 + 2 = 8,  83 = 512。另外一个有这个性质的数字是 614656=284

我们定义 an 为这个数列中的第 N 个元素,当然,起码得是两位数以上,才能求和。

已知 a2=512,a10=614656

请找出 A30
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-8-21 13:30:30 | 显示全部楼层
248155780267521,是对的吗?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-8-21 20:44:54 | 显示全部楼层
逝痕 发表于 2016-8-21 13:30
248155780267521,是对的吗?

我也是这结果248155780267521
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-8-21 20:46:03 | 显示全部楼层
代码如下
  1. result = []

  2. for i in range(2,100):
  3.     for j in range(2,100):
  4.         number = i**j
  5.         number = str(number)
  6.         length = len(number)
  7.         s = 0
  8.         num = []
  9.         for k in range(length):
  10.             num.append(int(number[k]))
  11.             s += num[k]
  12.         if s == i:
  13.             result.append(i**j)

  14. result.sort()
  15. a = result[30-1]

  16. print(a)
  17.         
  18.             
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 2 反对 0

使用道具 举报

发表于 2016-8-22 13:16:16 | 显示全部楼层

python果然简洁明了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-8-22 13:19:12 | 显示全部楼层
逝痕 发表于 2016-8-21 13:30
248155780267521,是对的吗?
  1. #include <iostream>
  2. #include <climits>
  3. #include <algorithm>
  4. #include <vector>

  5. bool interesting(unsigned long long x);        //判断数字是否符合要求

  6. int main() {
  7.         std::vector<unsigned long long> arr;
  8.         for (int i = 2; i < 180; i++) {
  9.                 unsigned long long temp = i;
  10.                 while (temp < ULLONG_MAX / i) {
  11.                         if (temp > 10){
  12.                                 arr.push_back(temp);
  13.                         }
  14.                         temp *= i;
  15.                 }
  16.         }
  17.         sort(arr.begin(), arr.end());
  18.         std::vector<unsigned long long>::iterator pos = unique(arr.begin(), arr.end());
  19.         arr.erase(pos, arr.end());                //除去重复的数字
  20.         int k = 1;
  21.         for (std::vector<unsigned long long>::iterator itr = arr.begin(); itr != arr.end(); itr++){
  22.                 if (interesting(*itr)) {
  23.                         std::cout << "a[" << k << "] = " << *itr << std::endl;
  24.                         k++;
  25.                 }
  26.                        
  27.         }
  28.         system("PAUSE");
  29.         return 0;
  30. }

  31. bool interesting(unsigned long long x) {
  32.         unsigned int sum = 0;
  33.         unsigned long long temp = x;
  34.         while (temp != 0){
  35.                 sum += temp % 10;
  36.                 temp /= 10;
  37.         }
  38.         if (sum == 1) {
  39.                 return false;
  40.         }
  41.         while (x != 1) {
  42.                 if (x % sum != 0){
  43.                         return false;
  44.                 }
  45.                 x /= sum;
  46.         }
  47.         return true;
  48. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-10-15 08:29:22 From FishC Mobile | 显示全部楼层
对于不支持大数运算的语言那简直就是灾难
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-20 16:52:54 | 显示全部楼层

结果是对的。但缺少数学上的证明这样做已经可以了。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-22 01:13

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表