博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Project Euler:Problem 32 Pandigital products
阅读量:5949 次
发布时间:2019-06-19

本文共 2013 字,大约阅读时间需要 6 分钟。

We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once; for example, the 5-digit number, 15234, is 1 through 5 pandigital.

The product 7254 is unusual, as the identity, 39 × 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital.

Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.

HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum.

We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once; for example, the 5-digit number, 15234, is 1 through 5 pandigital.

The product 7254 is unusual, as the identity, 39 × 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital.

Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.

HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum.

#include 
#include
using namespace std;bool pand(int a, int b, int c){ map
mp; int tmp[] = { a, b, c }; int num = 1; if (b != 0) num = 3; for (int i = 0; i < num; i++) { int p = tmp[i]; while (p) { if (mp[p % 10] != 0) return false; else { mp[p % 10] = 1; p = p / 10; } } } if (mp[0] != 0) return false; if (b == 0) //说明a中无反复 return true; int count = 0; for (int i = 1; i <= 9; i++) { if (mp[i] != 0) count++; } if (count == 9) return true; else return false;}int main(){ map
mp; for (int i = 1; i <= 9876; i++) { if (pand(i,0,0)) { for (int j = 1; j < i; j++) { if (i*j <= 10000) { if (pand(i, j, i*j)) mp[i*j] = 1; } } } } map
::iterator iter; int res = 0; for (iter = mp.begin(); iter != mp.end(); iter++) { if (mp[iter->first] == 1) res += iter->first; } cout << res << endl; system("pause"); return 0;}

转载地址:http://yrixx.baihongyu.com/

你可能感兴趣的文章
文件下载_中文乱码:"Content-disposition","attachment; filename=中文名
查看>>
HBase 笔记3
查看>>
2017.11.23 display fun --STM8
查看>>
深入学习jQuery选择器系列第八篇——过滤选择器之伪子元素选择器
查看>>
精简菜单和完整菜单之间进行切换
查看>>
一个关于log4j的悲伤的故事
查看>>
PCA
查看>>
ajax上传文件
查看>>
java中通过绝对路径将图片存入数据库
查看>>
简要记录浮点型数据的二进制存储格式
查看>>
ConcurrentHashMap(Java8)源码分析
查看>>
Python文件处理之文件指针(四)
查看>>
Numpy用法详解
查看>>
DataGridView在vb.net中的操作技巧
查看>>
PMP考试冲刺进行中。。。
查看>>
大换血的代价
查看>>
Learn in FCC(3)
查看>>
RunLoop--
查看>>
chrome 2行换行省略号 ... text-ellipse
查看>>
Python的virtualenv管理
查看>>