We are about to switch to a new forum software. Until then we have removed the registration on this forum.

- All Categories 25.7K
- Announcements & Guidelines 13
- Common Questions 30
- Using Processing 22.1K
- Programming Questions 12.2K
- Questions about Code 6.4K
- How To... 4.2K
- Hello Processing 72
- GLSL / Shaders 292
- Library Questions 4K
- Hardware, Integration & Other Languages 2.7K
- Kinect 668
- Arduino 1K
- Raspberry PI 188
- Questions about Modes 2K
- Android Mode 1.3K
- JavaScript Mode 413
- Python Mode 205
- Questions about Tools 100
- Espanol 5
- Developing Processing 548
- Create & Announce Libraries 211
- Create & Announce Modes 19
- Create & Announce Tools 29
- Summer of Code 2018 93
- Rails Girls Summer of Code 2017 3
- Summer of Code 2017 49
- Summer of Code 2016 4
- Summer of Code 2015 40
- Summer of Code 2014 22
- p5.js 1.6K
- p5.js Programming Questions 947
- p5.js Library Questions 315
- p5.js Development Questions 31
- General 1.4K
- Events & Opportunities 289
- General Discussion 365

I have the number 700821472143. I'm trying to apply Fermat's factorisation to find the greatest prime factor of it.

Here's my code so far:

```
long n = 700821472143L;
long[] results = new long[2];
boolean isInteger(float num) {
return num%1==0;
}
void run() {
for (int i=0; i < n; i++) {
if(isInteger(sqrt(n+i*i))) {
results[0] = (long)sqrt(n+i*i)+i;
results[1] = (long)sqrt(n+i*i)-i;
break;
}
}
}
void setup() {
run();
println(results[0] + " " + results[1]);
}
```

Now the problem with the above is that I can't even get this to give me the two factors of the form of (x-y)*(x+y) which make up my big value. There seem to be unavoidable rounding errors from Processing. I get 837,694 and 836,608. If I multiply those two numbers together on my calculator I don't get 700821472143... I get 700821**501952** . How can I avoid these errors?

## Answers

`float`

instead of`double`

.`long`

value's precision, use methods from`class`

Math instead:https://Docs.Oracle.com/javase/8/docs/api/java/lang/Math.html

`final double sqrtN = Math.sqrt(i*i + n)`

Thanks!