CF303D.Rotatable Number

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Bike is a smart boy who loves math very much. He invented a number called "Rotatable Number" inspired by 142857142857 .

As you can see, 142857142857 is a magic number because any of its rotatings can be got by multiplying that number by 1,2,...,61,2,...,6 (numbers from one to number's length). Rotating a number means putting its last several digit into first. For example, by rotating number 1234512345 you can obtain any numbers: 12345,51234,45123,34512,2345112345,51234,45123,34512,23451 . It's worth mentioning that leading-zeroes are allowed. So both 45001234500123 and 01234500123450 can be obtained by rotating 00123450012345 . You can see why 142857142857 satisfies the condition. All of the 66 equations are under base 1010 .

  • 1428571=142857142857·1=142857 ;
  • 1428572=285714142857·2=285714 ;
  • 1428573=428571142857·3=428571 ;
  • 1428574=571428142857·4=571428 ;
  • 1428575=714285142857·5=714285 ;
  • 1428576=857142142857·6=857142 .

Now, Bike has a problem. He extends "Rotatable Number" under any base bb . As is mentioned above, 142857142857 is a "Rotatable Number" under base 1010 . Another example is 00110011 under base 2. All of the 44 equations are under base 22 .

  • 00111=00110011·1=0011 ;
  • 001110=01100011·10=0110 ;
  • 001111=10010011·11=1001 ;
  • 0011100=11000011·100=1100 .

So, he wants to find the largest bb (1<b<x) so that there is a positive "Rotatable Number" (leading-zeroes allowed) of length nn under base bb .

Note that any time you multiply a rotatable number by numbers from 1 to its length you should get a rotating of that number.

输入格式

The only line contains two space-separated integers n,xn,x (1<=n<=5106,2<=x<=109)(1<=n<=5·10^{6},2<=x<=10^{9}) .

输出格式

Print a single integer — the largest bb you found. If no such bb exists, print -1 instead.

输入输出样例

  • 输入#1

    6 11
    

    输出#1

    10
    
  • 输入#2

    5 8
    

    输出#2

    -1
    
首页