1.


/**
* ACM
* UVa Status: accepted
* Run Time: 1.200
* Category: Math
* @author Evgeni Pavlidis evgenipavlidis@yahoo.de
*/
import java.util.*;
import java.io.*;

public class Main {

public static int MAX_PRIME = 5000000;
static boolean[] isPrime = new boolean[MAX_PRIME+1];
static int[] sum = new int[MAX_PRIME+1];
static int[] dePrimes = new int[MAX_PRIME+1];

static void generateDePrimes()
{
for(int i=2; i <= MAX_PRIME; i++)
isPrime[i] = true;

// we have to "seive" till MAX_PRIME(not sqrt(MAX_PRIME))
// to get the correct sum of the number
for(int i=2; i <= MAX_PRIME; i++)
if(isPrime[i])
for(int j=i+i; j <= MAX_PRIME; j+=i)
{
isPrime[j] = false;
sum[j] += i;
}

dePrimes[2] = 1;
for(int i=3; i <= MAX_PRIME; i++)
dePrimes[i] = dePrimes[i-1] + ((isPrime[i] || isPrime[sum[i]])? 1 : 0);
}


public static void main(String...args)
{
generateDePrimes();
int a,b;

Scanner scanner = new Scanner(System.in);
while(true)
{
a = scanner.nextInt();
if(a == 0)
break;
b = scanner.nextInt();

System.out.println((dePrimes[b] - dePrimes[a-1]));
}
}
}



2.


/**
* ACM
* UVa Status: accepted
* Run Time: 0.260
* Category: ad hoc, C++
* @author Evgeni Pavlidis evgenipavlidis@yahoo.de
*/
#include <iostream>
using namespace std;

static int s;
static int digits;
static string n;

static string space;
static string marked;

void printHead()
{
string result = " ";
for(int d=0; d<digits; d++)
{
if(n[d] != '1' && n[d] != '4')
result += marked;
else
result += space;

if(d < digits-1)
result += " ";
else
result += " ";
}

cout << result << endl;
}

void printUpperBody()
{
string result = "";
for(int d=0; d<digits; d++)
{
if(n[d] != '1' && n[d] != '2' && n[d] != '3' && n[d] != '7')
result += "|";
else
result += " ";

result += space;

if(n[d] < '5' || n[d] > '6')
result += "|";
else
result += " ";

if(d < digits-1)
result += " ";
}

cout << result << endl;
}

void printMiddle()
{
string result = " ";
for(int d=0; d<digits; d++)
{
if(n[d] != '1' && n[d] != '7' && n[d] != '0')
result += marked;
else
result += space;

if(d < digits-1)
result += " ";
else
result += " ";
}

cout << result << endl;
}

void printLowerBody()
{
string result = "";
for(int d=0; d<digits; d++)
{
if(n[d] == '2' || n[d] == '6' || n[d] == '8' || n[d] == '0')
result += "|";
else
result += " ";

result += space;

if(n[d] != '2')
result += "|";
else
result += " ";

if(d < digits-1)
result += " ";
}

cout << result << endl;
}

void printFeet()
{
string result = " ";
for(int d=0; d<digits; d++)
{
if(n[d] != '1' && n[d] != '4' && n[d] != '7')
result += marked;
else
result += space;

if(d < digits-1)
result += " ";
else
result += " ";
}

cout << result << endl;
}


int main()
{
while(true)
{
cin >> s;
if(s == 0)
return 0;
cin >> n;

digits = n.length();

space = "";
marked = "";
for(int i=0; i<s; i++)
{
space += " ";
marked += "-";
}

printHead();
for(int i=0; i < s; i++)
printUpperBody();
printMiddle();
for(int i=0; i < s; i++)
printLowerBody();
printFeet();

cout << endl;
}
}