I am trying to make a program with the problem "Given a positive integer a, what is the minimum positive integer g such that g! is a multiple of the square of a!?
Sample Input
1 (test case)
4
Sample Output
8
Explanation: 8!=40320 is divisible by 4!^2=24^2=576. Furthermore, it is the smallest one because 7!=5040 is not divisible by 576.
The program is successful, but i'm having trouble when the input is larger than about 20. It wont output anything.
Any suggestions?
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
long long a,b,c=1,d,e=1,f=1,g=0,k;
cin>>a;
while(a>0){
cin>>b;
g=0;
e=1;
c=1;
f=1;
for (long long i=1; i<=b; i++){
c=c*i;
}
d=c*c;
for(long long j=1; e!=0; j++){
f=f*j;
g=g+2;
e=f%d;
if(c==e)
cout<<g<<endl;
}
a--;
}
return 0;
}