Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2012 /finals /maximal_multiplicative_order.html
wjomlex's picture
2012 Problems
91a79e0 verified
raw
history blame
2.21 kB
<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> &#8722; 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> &#8722; 1 = 7</b> is divisible by <b>7</b> but <b>2<sup>1</sup> &#8722; 1</b> and <b>2<sup>2</sup> &#8722; 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 &le; a &le; 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 &le; 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 &#8804; R</b> the product
<p><center><b>N(L) &#8729; N(L+1) &#8729; ... &#8729; 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 &le; T &le; 20<br/>
1 &le; L &le; R &le; 10<sup>12</sup><br/>
R &#8722; L &le; 500000</b><br/></p>