Skip to content

Instantly share code, notes, and snippets.

@joemmanuel
Created October 8, 2013 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joemmanuel/6885731 to your computer and use it in GitHub Desktop.
Save joemmanuel/6885731 to your computer and use it in GitHub Desktop.
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