Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Solución de subprimos de diego_futbolm
#include <cstdlib>
#include <iostream>
#include <string.h>
using namespace std;
bool esprimo[100005];
int fact[100005], n;
bool es_primo(int n)
{
int si;
si = 1;
for(int j = 2; j * j <= n; j++)
if(n % j == 0)
si = 0;
if(si == 0)
return false;
return true;
}
int cuenta(int num, int j)
{
fact[num] = fact[j] + fact[num / j];
return fact[j] + fact[num / j];
}
int main()
{
int a, b, i, count, c, j, primero;
cin >> a >> b;
memset(fact, 0, sizeof(fact));
for(i = 0; i <= b; i++)
{
esprimo[i] = false;
if(i >= 2)
{
if(es_primo(i))
{
esprimo[i] = true;
fact[i] = 1;
}
}
}
c = 0;
for(n = 2; n <= b; n++)
{
if(!esprimo[n])
{
primero = 0;
for(j = 2; primero == 0 && j * j <= n; j++)
{
if(n % j == 0)
{
count = cuenta(n, j);
primero = 1;
}
}
if(n >= a && n <= b && esprimo[count])
c++;
}
}
cout << c;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment