invalid operands of types 'float' and 'float' to binary 'operator%'

I am trying to fidn the largest prime factor of a very large number so i used float but i am getting this error.

#include<iostream>
using namespace std;

void pf(float n)
{
float i;

for(i=2;i<=n;i++)
{
if(n%i==0)
{
n=n/i;
cout<<i<<"\n";
i--;
}

}
}

int main()
{
pf(600851475143 );
return 0;
}
fmod function. Use that for floating types.

your number will fit into a 64 bit integer, fyi.

you only need to check up to (or down to, if reverse) sqrt N, in your loop, also.
Brute force is not so hot here, but you can at least greatly reduce the work done with that tweak. When you find a factor, divide the number by it and pick up its counter, for example if it divides by 3, you can pick up 3*x = yournumber, solve for x (yournumber/3). Factors come in pairs.

the first factor you find, its counterpart is the largest factor, then need to check if that # is prime. I cant see that you check to see if your factors are prime here (?).
Last edited on
Topic archived. No new replies allowed.