|
<p>Let's start with some notations and definitions. Let <b>m</b> be the fixed positive integer.</p> |
|
|
|
<ol> |
|
<li> Let <b>a</b> be an integer that coprime to <b>m</b>, that is, <b>gcd(a, m) = 1</b>. The minimal positive integer <b>k</b> such that <b>m</b> divides <b>a<sup>k</sup> − 1</b> is called the <i>multiplicative order of <b>a</b> modulo <b>m</b></i> and denoted as <b>ord<sub>m</sub>(a)</b>. For example, <b> ord<sub>7</sub>(2) = 3</b> since <b>2<sup>3</sup> − 1 = 7</b> is divisible by <b>7</b> but <b>2<sup>1</sup> − 1</b> and <b>2<sup>2</sup> − 1</b> are not. It can be proven that <b>ord<sub>m</sub>(a)</b> exists for every <b>a</b> that coprime to <b>m</b>. |
|
|
|
<li> Denote by <b>L(m)</b> the maximal possible multiplicative order of some number modulo <b>m</b>. That is, <b>L(m) = max{ord<sub>m</sub>(a) : 1 ≤ a ≤ m, gcd(a, m)=1}</b>. For example, <p><center><b>L(5) = max{ ord<sub>5</sub>(1), ord<sub>5</sub>(2), ord<sub>5</sub>(3), ord<sub>5</sub>(4)} = max{1, 4, 4, 2} = 4</b></center></p> and <p><center><b>L(6) = max{ord<sub>6</sub>(1), ord<sub>6</sub>(5)} = max{1, 2} = 2.</b></center></p> |
|
|
|
<li> Denote by <b>N(m)</b> the number of positive integers <b>a ≤ m</b> such that <b> ord<sub>m</sub>(a) = L(m)</b>. For example, <b>N(5) = 2</b>, <b>N(6) = 1</b>, <b>N(8) = 3</b> (numbers that have maximal multiplicative order modulo <b>8</b> are <b>3, 5</b> and <b>7</b>). |
|
</ol> |
|
<p>Now your task is to find for the given positive integers <b>L</b> and <b>R</b> such that <b>L ≤ R</b> the product |
|
<p><center><b>N(L) ∙ N(L+1) ∙ ... ∙ N(R)</b></center></p> |
|
modulo <b>10<sup>9</sup> + 7</b>.</p> |
|
|
|
<h3>Input</h3> |
|
<p>The first line contains a positive integer <b>T</b>, the number of test cases. <b>T</b> test cases follow. The only line of each test case contains two space separated positive integers <b>L</b> and <b>R</b>.</p> |
|
|
|
<h3>Output</h3> |
|
<p>For each of the test cases numbered in order from <b>1</b> to <b>T</b>, output "Case #i: " followed by the value of required product modulo <b>10<sup>9</sup> + 7</b>.</p> |
|
|
|
<h3>Constraints</h3> |
|
<p> |
|
<b>1 ≤ T ≤ 20<br/> |
|
1 ≤ L ≤ R ≤ 10<sup>12</sup><br/> |
|
R − L ≤ 500000</b><br/></p> |
|
|
|
|