CF1673D Lost Arithmetic Progression
Description
Long ago, you thought of two finite [arithmetic progressions](https://en.wikipedia.org/wiki/Arithmetic_progression) $ A $ and $ B $ . Then you found out another sequence $ C $ containing all elements common to both $ A $ and $ B $ . It is not hard to see that $ C $ is also a finite arithmetic progression. After many years, you forgot what $ A $ was but remember $ B $ and $ C $ . You are, for some reason, determined to find this lost arithmetic progression. Before you begin this eternal search, you want to know how many different finite arithmetic progressions exist which can be your lost progression $ A $ .
Two arithmetic progressions are considered different if they differ in their first term, common difference or number of terms.
It may be possible that there are infinitely many such progressions, in which case you won't even try to look for them! Print $ -1 $ in all such cases.
Even if there are finite number of them, the answer might be very large. So, you are only interested to find the answer modulo $ 10^9+7 $ .
Input Format
N/A
Output Format
N/A
Explanation/Hint
For the first testcase, $ B=\{-3,-2,-1,0,1,2,3\} $ and $ C=\{-1,1,3,5\} $ . There is no such arithmetic progression which can be equal to $ A $ because $ 5 $ is not present in $ B $ and for any $ A $ , $ 5 $ should not be present in $ C $ also.
For the second testcase, $ B=\{-9,-6,-3,0,3,6,9,12,15,18,21\} $ and $ C=\{0,6,12\} $ . There are $ 10 $ possible arithmetic progressions which can be $ A $ :
- $ \{0,6,12\} $
- $ \{0,2,4,6,8,10,12\} $
- $ \{0,2,4,6,8,10,12,14\} $
- $ \{0,2,4,6,8,10,12,14,16\} $
- $ \{-2,0,2,4,6,8,10,12\} $
- $ \{-2,0,2,4,6,8,10,12,14\} $
- $ \{-2,0,2,4,6,8,10,12,14,16\} $
- $ \{-4,-2,0,2,4,6,8,10,12\} $
- $ \{-4,-2,0,2,4,6,8,10,12,14\} $
- $ \{-4,-2,0,2,4,6,8,10,12,14,16\} $
For the third testcase, $ B=\{2,7,12,17,22\} $ and $ C=\{7,12,17,22\} $ . There are infinitely many arithmetic progressions which can be $ A $ like:
- $ \{7,12,17,22\} $
- $ \{7,12,17,22,27\} $
- $ \{7,12,17,22,27,32\} $
- $ \{7,12,17,22,27,32,37\} $
- $ \{7,12,17,22,27,32,37,42\} $
- $ \ldots $