public static void main(String[] args)
	{
		long sum = 0;
		ArrayList<Long> possibles = new ArrayList<Long>();
		for (long i = 1L; i < 10; i++)
			possibles.add(i);
		for (int i = 0; i < 14; i++)
		{
			int size = possibles.size();
			for (int j = 0; j < size; j++)
			{
				long current = possibles.remove(0);
				
				if (i>0 && strongHarshadNumber(Long.parseLong((current+"").substring(0,(current+"").length()-1))) && isPrime(current))
					sum += current;
				
				if (harshadNumber(current))
					for (int k = 0; k < 10; k++)
						possibles.add(Long.parseLong(""+current+k));
			}
		}
		
		System.out.print(sum);
		
	}