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. excel合并同类项去重求和功能

    参考:百度经验 主要利用函数为:sumif(range,criteria,[sum_range]) Range:条件区域,用于条件判断的单元格区域. Criteria:求和条件,由数字.逻辑表达式等组 ...

  2. FlipViewDemo

    error: Resource entry white is already defined. error: Resource entry transparentBlack is already de ...

  3. Apk反编译助手

    Android是一个让人很纠结的产品,它开源开放,但是也有很多蛋疼坑爹的地方,还是那句话,谁开发谁知道! Apk反编译助手,懒人和对command line无爱的同学们可下载看看,至少需要.net 2 ...

  4. 有效利用番茄工作法提高效率--XorTime的使用方法

      之前下载过番茄工作法XorTime,但是一直不知道怎么用,我想很多朋友应该也会遇到这种情况,于是我通过网上查找并直接总结,把XorTime的使用方法给写下,希望能够帮到更多的朋友..        ...

  5. Javascript 计算字符串所占字节数

    最近项目有个需求要用js计算一串字符串写入到localStorage里所占的内存,众所周知的,js是使用Unicode编码的.而Unicode的实现有N种,其中用的最多的就是UTF-8和UTF-16. ...

  6. 数据结构学习之stack

    不能小看这些基本的数据结构,写了才发现还是会有问题出现的. 有码有真相: #pragma once class MyStack { public: MyStack(void); ~MyStack(vo ...

  7. Mysql DBA 20天速成教程

    Mysql DBA 20天速成教程 基本知识1.mysql的编译安装2.mysql 第3方存储引擎安装配置方法3.mysql 主流存储引擎(MyISAM/innodb/MEMORY)的特点4.字符串编 ...

  8. ruby的sort方法的重新认识

    ruby中的sort方法,这个方法可以加一个两个参数的block,这个block可以返回1 0 -1来表示这两个参数大于 等于 小于示例: str = ["192.160.175" ...

  9. React(0.13) 定义一个动态的组件

    1.因为jsx将两个花括号之间的内容渲染为动态值,只需要引用对应的变量即可 <!DOCTYPE html> <html> <head> <title>R ...

  10. hadoop下载地址

    hadoop下载地址 http://mirror.bit.edu.cn/apache/hadoop/common/ hadoop下载地址