stuff
This commit is contained in:
46
test_computation.c
Normal file
46
test_computation.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
FILE *file1 = fopen("input.bin", "rb");
|
||||
if (!file1) {
|
||||
perror("Error opening input.bin");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int n;
|
||||
if (fread(&n, sizeof(n), 1, file1) != 1) {
|
||||
perror("Error reading input.bin");
|
||||
fclose(file1);
|
||||
return 1;
|
||||
}
|
||||
fclose(file1);
|
||||
|
||||
printf("Got: %d\n", n);
|
||||
|
||||
// Primes or smth
|
||||
int count = 0;
|
||||
|
||||
for (int i = 2; i < 500000; i++) {
|
||||
int prime = 1;
|
||||
for (int d = 2; d * d <= n; d++) {
|
||||
if (n % d == 0) {
|
||||
prime = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
count += prime;
|
||||
n += 2;
|
||||
}
|
||||
|
||||
FILE *file2 = fopen("output.bin", "wb");
|
||||
if (!file2) {
|
||||
perror("Error opening output.bin");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fwrite(&count, sizeof(count), 1, file2);
|
||||
fclose(file2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user