F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Law of Commutation

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 893    Accepted Submission(s): 326


Problem Description
As we all know, operation ''+'' complies with the commutative law. That is, if we arbitrarily select two integers $a$ and $b$, $a + b$ always equals to $b + a$. However, as for exponentiation, such law may be wrong. In this problem, let us consider a modular exponentiation. Give an integer $m = 2^n$ and an integer $a$, count the number of integers $b$ in the range of $[1,m]$ which satisfy the equation $a^b \equiv b^a$ (mod $m$).
 

Input
There are no more than $2500$ test cases.

Each test case contains two positive integers $n$ and a seperated by one space in a line.

For all test cases, you can assume that $n \leq 30, 1 \leq a \leq 10^9$.
 

Output
For each test case, output an integer denoting the number of $b$.
 

Sample Input
2 3 2 2
 

Sample Output
1 2
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 07:15:56, Gzip enabled