We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<bits/stdc++.h>usingnamespacestd;#define ull unsigned longset<ull>pent;voidgenerate(){ulltemp;for(ulln=1;n<=1000000;n++){temp=n*(3*n-1)/2;pent.insert(temp);}}intmain(){/* Enter your code here. Read input from STDIN. Print output to STDOUT */generate();ullN,K;cin>>N>>K;for(ulln=K+1;n<=N;n++){ulldiff=n*(3*n-1)/2-(n-K)*(3*(n-K)-1)/2;ulladd=n*(3*n-1)/2+(n-K)*(3*(n-K)-1)/2;if(pent.count(diff)||pent.count(add)){cout<<n*(3*n-1)/2<<endl;}}return0;}
Accurate and Perfect solution of this problme
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #44: Pentagon numbers
You are viewing a single comment's thread. Return to all comments →
Accurate and Perfect solution of this problme