403539: GYM101192 A LIS and GCD
Memory Limit:0 MB
Time Limit:0 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
A. LIS and GCDtime limit per test7.0 smemory limit per test512 MBinputstandard inputoutputstandard output1 ≤ n ≤ 105 1 ≤ ai ≤ 109 1 ≤ bi ≤ 106 Output
You are given two arrays a and b. Each array has n integer numbers. You need to compute the sum of GCDs of all subsequences of array b such that the corresponding subsequences of array a are increasing.
InputThe first input line contains one integer number n. The second line contains n integer numbers ai. The third line contains n integer numbers bi.
Display the answer modulo 109 + 7.
ExamplesInput2Output
1 2
1 2
4Input
2Output
2 1
1 2
3Input
4Output
2 3 1 4
2 3 6 9
29Note
Third example: Here are examples of increasing subsequences from a and the corresponding GCD values: {2}->2, {3}->3, {1}->6, {4}-> 9, {2,3}->1, {2,4}->1, {3,4}->3, {1,4}->3, {2,3,4}->1.