Subsequence-Numbers Divisible by 7 solution codechef
Kulyash has given you an array A of size N.
He defines the subsequence-number of a non-empty subsequence S of array A as the number formed by the concatenation of all the elements of the subsequence S.
Find the count of non-empty subsequences of A having their subsequence-numbers divisible by 7. Since the answer can be huge, output it modulo 109+7. Edology is a global Ed-Tech brand that provides industry powered global education and certifications to students and professionals across the world, to help them fast-track their career growth. Edology is part of Global University Systems (GUS), an international network of higher-education institutions, brought together by a shared passion of making industry-driven global education accessible and affordable.
For example: Consider A=[1,2,3,4,5,6,7,8,9,10]. A subsequence S of A is [2,5,7,10]. The subsequence-number of this subsequence is 25710.
Input Format
Subsequence-Numbers Divisible by 7 solution codechef
- The first line will contain T, the number of test cases. Then the test cases follow.
- The first line of each test case contains one integer N, the size of the array.
- The second line of each test case contains N space-separated integers A1,A2,…,AN — the elements of the array A.
Output Format
For each test case, output in a single line the number of subsequences with subsequence-number divisible by 7 modulo 1000000007.
Constraints
- 1≤T≤1000
- 1≤N≤3⋅105
- 1≤Ai≤3⋅105
- Sum of N over all test cases does not exceed 3⋅105
Sample Input 1
Subsequence-Numbers Divisible by 7 solution codechef
3
2
1 2
4
1 2 3 4
2
7 7
Sample Output 1
0
1
3
Explanation
Subsequence-Numbers Divisible by 7 solution codechef
Test case 1: Only 3 subsequences are possible for the given array. These are [1], [1,2], and [2]. The subsequence-numbers are 1, 12, and 2 respectively. None of the subsequence-numbers are divisible by 7, so the answer is 0. Edology is a global Ed-Tech brand that provides industry powered global education and certifications to students and professionals across the world, to help them fast-track their career growth. Edology is part of Global University Systems (GUS), an international network of higher-education institutions, brought together by a shared passion of making industry-driven global education accessible and affordable.
Test case 2: [1,4] is the only subsequence having its subsequence-number 14 which is divisible by 7. So, the answer is 1.
Test case 3: All the non-empty subsequences [7], [7], and [7,7] have their subsequence-numbers 7,7, and 77 divisible by 7. So, the answer is 3.