Esempio n. 1
0
int main(int argc, char* argv[]) {
  uint64_t m,n,s,d,l,x,y,z;
  uint32_t a=1,b,c,i,j;
  x=y=z=0-1;

  if(argc > 1 && !strcmp(argv[1],"--help")) { return print_help(argv[0]); }

  for(i=5,l=0; a; ++i,l=m) {
    m = getPent(i);
    if(m-l > z) /* break when minimum found */
      break;
    for(j=i-1; j>0; --j) {
      n = getPent(j);
      s = m + n;
      d = m - n;
      b = isPent(s);
      c = isPent(d);
      if(b && c) {
        a = 0;
        x = m;
        y = n;
        z = d; /* difference to be minimized */
      }
    }
  }
  /* print result */
  printf("%llu - %llu = %llu\n",x,y,z);
  return 0;
}
Esempio n. 2
0
int main ()
{
	long				curNum = 1;
	std::vector<long>	pentList;
	std::vector<bool>	isPent(MAX, false);

	for(int i = 1; curNum < MAX ; i += 3, curNum += i)
	{
		//Create list of pentagonal numbers
		pentList.push_back(curNum);

		//Create look up table of pentagonal numbers
		isPent[curNum] = true;
	}

	int endLoop = pentList.size();
	for(int i = 0; i < endLoop; ++i)
	{
		for(int j = i; j < endLoop; ++j)
		{
			//This condition prevents segfaulting even though it shouldn't be needed
			//Reason: Unknown
			if(pentList[i] + pentList[j] > MAX ||
			   pentList[j] - pentList[i] < 0)
			{
				break;
			}
			else if(isPent[pentList[i] + pentList[j]] &&
			   		isPent[pentList[j] - pentList[i]])
			{
				std::cout << pentList[i] << " " << pentList[j] << " " << pentList[j] - pentList[i] << std::endl;
			}
			else {}
		}
	}

	return 0;
}