Untitled
unknown
csharp
2 years ago
1.0 kB
19
Indexable
static void Main(String[] args) { List<int> list2 = new List<int>() { 422346306, 940894801, 696810740, 862741861, 85835055, 313720373 }; int k = 9; var z = nonDivisibleSubset(k, list2); } public static int nonDivisibleSubset(int k, List<int> s) { var x = GetPerm(s); var y = x.Where(x => x.Value % k != 0).Select(x=>x.Key).ToList(); var a = y.SelectMany(x => x).ToHashSet(); return a.Count(); } static Dictionary<List<int>,int> GetPerm (List<int> list) { Dictionary<List<int>,int> perm = new Dictionary<List<int>, int>(); for (int i = 0; i < list.Count; i++) { for (int j = i+1; j < list.Count; j++) { List<int> sumCouple = new List<int>(); sumCouple.Add(list[i]); sumCouple.Add(list[j]); perm.Add(sumCouple, sumCouple.Sum()); } } return perm; }
Editor is loading...