Created
November 19, 2017 21:17
-
-
Save mpampols/fd4afd46595744fe8d7ea58e8b994ff3 to your computer and use it in GitHub Desktop.
Solución al reto 2 de la Semic Challenge del grupo "josep_pon" en la HackEPS 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <fstream> | |
#include <sstream> | |
#include <iostream> | |
#include <gmp.h> | |
using namespace std; | |
void print_nums(unsigned int a1, unsigned int b1, int contador) | |
{ | |
mpz_t a,b,n,suma; | |
mpz_init_set_ui(a,a1); | |
mpz_init_set_ui(b,b1); | |
mpz_init_set_ui(suma,a1); | |
mpz_init(n); | |
mpz_nextprime (n, a); | |
while (mpz_cmp ( n,b) <= 0) | |
{ | |
mpz_add(suma,suma,n); | |
mpz_nextprime(n,n); | |
} | |
gmp_printf ("Case #%d: %Zd\n",contador, suma); | |
} | |
int main() | |
{ | |
std::ifstream file("input.txt"); | |
int value1,value2, quant, contador=1; | |
std::string line; | |
std::getline(file, line); | |
std::stringstream lineStream(line); | |
lineStream >> quant; | |
while(std::getline(file, line)) | |
{ | |
std::stringstream lineStream(line); | |
while(lineStream >> value1 >> value2) | |
print_nums(value1,value2,contador++); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment