ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1586. Threeprime Numbers

C# solution
Posted by InDevRus 9 Jun 2017 07:03
using System;
using System.Collections.Generic;
using System.Linq;

{
public static class IntExtensions
{
public static bool IsPrime(this int number)
{
for (var divisor = 2; divisor < number; divisor++)
if (number % divisor == 0)
return false;
return true;
}
}
internal static class Solver
{
() => Enumerable.Range(100, 900).Where(number => number.IsPrime());
private static Dictionary<int, IEnumerable<int>> PrefixCorrespondance(IEnumerable<int> primeNumbers)
{
.GroupBy(number => number / 10)
.ToDictionary(group => group.Key, group => group.Select(item => item));
}
internal static long Solve(int digitCount)
{
var table = new long[digitCount - 2, 90];
for (var counter = 10; counter < 100; counter++)
table[0, counter - 10] = (prefixes.TryGetValue(counter, out var collection)) ? collection.Count() : 0;
for (var counter = 1; counter <= digitCount - 3; counter++)
foreach (var pair in prefixes)
{
var suffix = primeNumber % 100 - 10;
table[counter, pair.Key - 10] += (suffix < 0) ? 0 : table[counter - 1, suffix];
table[counter, pair.Key - 10] %= 1000000009;
}
long sum = 0;
for (var counter = 0; counter < 90; counter++)
sum = (sum + table[digitCount - 3, counter]) % 1000000009;
return sum;

}
public static void Main()
{