-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem42.cpp
More file actions
48 lines (43 loc) · 731 Bytes
/
Problem42.cpp
File metadata and controls
48 lines (43 loc) · 731 Bytes
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
/*
Krishna Mohan
Project Euler - Problem 42
Date: 3/24/2015
*/
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for(int (i)=0;(i)<(n); (i)++)
#define MAX 1000001
bitset<MAX> isTriNum;
void init()
{
int i=1, tn=0;
isTriNum.reset();
while(true)
{
tn=(i*(i+1))/2;
if(tn>=MAX)
break;
isTriNum[tn]=1;
i++;
}
}
int main()
{
ios_base::sync_with_stdio(0);
int num=0, sz, cnt=0;
string str;
init();
while(cin>>str)
{
sz=str.size();
num=0;
fo(i, sz)
{
num+=str[i]-'A'+1;
}
if(isTriNum[num])
cnt++;
}
cout<<"Ans: "<<cnt<<endl;
return 0;
}