编程介的小学生 2017-08-31 02:14 采纳率: 20.5%
浏览 636
已采纳

Secret Code

When you want to send a message, could you imagine what would happen if you don't encrypt it? The Hackers may get your information, which may be critical for you such as your bank account and password. So we try to encrypt the message into "Secret Code" before sending it. But now your task is not to encrypt the message, but to "operate" on the "Secret Code".

First of all, I will tell you how we encrypt a single small letter C into the "Secret Code" (Note that we only take small letters into consideration).

  1. We could get a value A from C by the following expression.

A = Fun(C); //Here Fun(C) generates an integer in the range[1, 2^31 - 1] associated with C, but we don't care what the function's expression is;

  1. Let B = Fun2(theASCIIvalueOf(C)), note theASCIIvalueOf('a') is 97 and Fun2(theASCIIvalueOf(C)) generates an integer in the range[1, 2^31 - 1] associated with theASCIIvalueOf(C), but we don't care what the function's expression is;

  2. Calculate D = AB mod P, here P is a given integer.

  3. D is the "Secret Code" for the small letter C.

Now I will tell you how to "operate" the "Secret Code": Find all the numbers that satisfy the following rules:

  1. Ax = D (mod P)

  2. 0 <= x <= M, here M is a given integer.

Now your task is so simple: you are given A, P, D and M, please tell me the number of numbers that satisfy the two rules above.

Input

There are multiply cases (<30), process to the end of file.

Every case contains only four integers indicating A, P, D, M (1 <= A, P < 2^31, 0 <= D < P, 1 <= M < 2^63).

Ouput

For each case, you should output a single line indicates the answer as describe above.

Sample Input

2 16 8 10
5 10 5 11
Sample Output

1
11

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-09-14 16:20
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型