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 <iostream>
#include <map>
using namespace std; bool pand(int a, int b, int c)
{
map<int, int>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<int, int>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<int, int>::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;
}

Project Euler:Problem 32 Pandigital products的更多相关文章

  1. Project Euler: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 ...

  2. 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 ...

  3. Project Euler:Problem 55 Lychrel numbers

    If we take 47, reverse and add, 47 + 74 = 121, which is palindromic. Not all numbers produce palindr ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. Project Euler:Problem 93 Arithmetic expressions

    By using each of the digits from the set, {1, 2, 3, 4}, exactly once, and making use of the four ari ...

  9. Project Euler:Problem 58 Spiral primes

    Starting with 1 and spiralling anticlockwise in the following way, a square spiral with side length ...

随机推荐

  1. hbuilder mui uploader图片上传到服务器完整版(ASP.NET)

    html布局,比较简单,模仿微信的: <div class="dynamic_images"> <ul> <!--<li><img  ...

  2. 转:Bullet物理引擎不完全指南(Bullet Physics Engine not complete Guide)

    write by 九天雁翎(JTianLing) -- blog.csdn.net/vagrxie 讨论新闻组及文件 前言 Bullet据称为游戏世界占有率为第三的物理引擎,也是前几大引擎目前唯一能够 ...

  3. 2、redis原生的命令操作不同数据类型

    一.常用数据类型简介: redis常用五种数据类型:string,hash,list,set,zset(sorted set). 1.String类型 String是最简单的类型,一个key对应一个v ...

  4. CTRL+SHIFT

    CTRL+SHIFT+鼠标左右,上下拖动,可快速实现平行和垂直上下复制的功能,

  5. ISCSI测试

    Initiator为应用客户端,服务端Target包括设备服务器端和队列管理两部分.服务端两种共享方式:1.在服务端共享分区2.在服务端以文件方式作为共享设备共享出来 构建ISCSI网络存储 测试环境 ...

  6. Heroku第三方服务接入指南(二)

    上文我们讲了第三方服务.Heroku.用户三者的关系,这一篇进入正题,了解第三方厂商(下文简称厂商)怎样为Heroku开发服务.这里仅仅做简介,了解heroku大致是怎么做的.假设你的平台.希望接入第 ...

  7. Echart示例

    echart.html:  需要注意js文件加载的顺序 <!DOCTYPE html> <html lang="en"> <head> < ...

  8. Emacs显示光标在哪个函数

    Emacs24中打开which-function-mode即可. 在.emacs中添加一行: (which-function-mode 1) 调整which-function在mode-line中的显 ...

  9. java.lang.IllegalArgumentException: Minimum column number is 0

    easyUI的datagrid导出Excel时报如下错误: [2018-06-20 15:00:21] [ERROR] [org.jeecgframework.poi.excel.export.Exc ...

  10. std::bind 详解及参数解析

    // Bind_std_function.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> ...