-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem32.cpp
More file actions
65 lines (63 loc) · 2.44 KB
/
Problem32.cpp
File metadata and controls
65 lines (63 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
Krishna Mohan
Project Euler - Problem 32
Date: 3/22/2015
*/
#include <bits/stdc++.h>
using namespace std;
#define MAX 2999
int main() {
int m[10], temp, ans, f;
set<int> s;
for(int i=1;i<=MAX;i++)
{
for(int j=1;j<=MAX;j++)
{
ans=i*j;
memset(m, 0, sizeof(m));
temp=i;
while(temp)
{
m[temp%10]++;
temp/=10;
}
temp=j;
while(temp)
{
m[temp%10]++;
temp/=10;
}
temp=ans;
while(temp)
{
m[temp%10]++;
temp/=10;
}
f=0;
if(m[0]!=0)
f=1;
for(int k=1;k<10;k++)
{
if(m[k]!=1)
{
f=1; break;
}
}
if(!f)
{
//cout<<i<<" * "<<j<<" = "<<ans<<endl;
s.insert(ans);
}
}
}
int sz=s.size();
int sum=0;
for(set<int>::iterator it=s.begin();it!=s.end(); it++)
{
//cout<<"In Set: "<<(*it)<<endl;
sum+=(*it);
//cout<<"In Set: "<<(*it)<<" Sum: "<<sum<<endl;
}
cout<<"Ans: "<<sum<<endl;
return 0;
}