-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem48.cpp
More file actions
72 lines (68 loc) · 1.38 KB
/
Problem48.cpp
File metadata and controls
72 lines (68 loc) · 1.38 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
66
67
68
69
70
71
72
/*
Krishna Mohan
Project Euler - Problem 48
Date: 3/24/2015
*/
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for(int (i)=0;(i)<(n); (i)++)
#define MAX 1001
int dat[MAX][MAX];
int main()
{
ios_base::sync_with_stdio(0);
int num, len=0, carry=0, sum;
for(int i=1;i<MAX;i++)
{
num=i;
len=0;
while(num)
{
dat[i][len++]=num%10;
num/=10;
}
/*for(int j=0;j<len;j++)
cout<<dat[i][j];
cout<<" -> ";*/
for(int j=1;j<i;j++)
{
carry=0;
for(int k=0;k<len;k++)
{
dat[i][k]=dat[i][k]*i+carry;
carry=dat[i][k]/10;
dat[i][k]%=10;
}
if(len>75)
continue;
while(carry)
{
dat[i][len++]=carry%10;
carry/=10;
}
}
/*for(int j=0;j<len;j++)
cout<<dat[i][j];
cout<<endl;*/
}
carry=0;
vector<int> ans;
for(int j=0;j<10;j++)
{
sum=0;
for(int i=0;i<MAX;i++)
{
sum+=dat[i][j];
}
sum+=carry;
carry=sum/10;
ans.push_back(sum%10);
}
reverse(ans.begin(), ans.end());
for(int i=0;i<ans.size();i++)
{
cout<<ans[i];
}
cout<<endl;
return 0;
}