M
M
Maqsat Batyrqul2015-10-22 23:12:42
C++ / C#
Maqsat Batyrqul, 2015-10-22 23:12:42

How to solve a problem in C++?

Write a program that will determine and display one factor out of N that can be omitted from the product
of 1! x2! x 3! x ... x N! so that the remaining product is an exact square.
PS it is clear that

one! x2! x 3! x4! = 122
if you remove 2! then everything is correct, but if N is odd, for example 5,7,9, then what to do?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maqsat Batyrqul, 2015-11-01
@Maqsat

#include<iostream>
using namespace std;

double faktorial(int n)
{
  if (n == 0) return 1;
  return n*faktorial(n - 1);
}
double isSquare(float n)
{
  double k;
  if (n == 0) return  0;
  k = sqrt(n);
  if (k == (int)k) return 1;
  else return 0;
}

int main()
{
  int n,temp;
  double f, s = 1;
  bool flug = true;
  cin >> n;

  for (size_t i = 1; i <= n; i++)
  {
    s *= faktorial(i);
  }
  cout << isSquare(s) << endl;

  for (size_t i = 0; i < n; i++)
  {
    temp = n - i;
    f = s / temp;
    if (isSquare(f))
    {
      cout << temp << endl;
      flug = false;
      break;
    }
  }
  if (flug) cout << "Not found "<<endl;
  system("pause");
  return 0;

}

M
Mrrl, 2015-10-22
@Mrl

Where did the task come from? Is there a link to the original? Are there any examples there?
While the impression that the authors wanted something else.

V
Vladimir Martyanov, 2015-10-22
@vilgeforce

In this case, "help" - decide for you? No thanks, no need...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question