#P3307. [SDOI2013] 项链
[SDOI2013] 项链
Description
Recently, Mingming has become obsessed with a certain kind of necklace. It is basically the same as other pearl necklaces, but its beads are special: they are carved from Taishan stone into regular triangular prisms.
The prism has three square lateral faces, and each face is engraved with a number. A necklace that satisfies Mingming must meet the following conditions:
- The necklace consists of beads.
- On each bead, every number must satisfy , and the greatest common divisor of the three numbers on the bead must be exactly .
- Adjacent beads must be different. Two beads are considered the same if and only if they can be made identical by rotation or reflection.
- Two necklaces are considered the same if they can become identical after a rotation.
Mingming is curious: given and , how many different necklaces are there? Since the answer can be large, output it modulo .
Input Format
This problem contains multiple test cases.
The first line contains an integer , the number of test cases.
Then follow lines, each containing two integers and .
Output Format
For each test case, output one integer, the number of different necklaces.
1
2 2
3
Hint
There are three kinds of beads that meet the conditions: [1,1,1], [1,1,2], [1,2,2].
The valid sequences they can form are: [1,2], [1,3], [2,3].
For of the testdata, it is guaranteed that , , .
Translated by ChatGPT 5
京公网安备 11011102002149号