旅行前的准备 (25分) 您所在的位置:网站首页 玩遍整个世界 旅行前的准备 (25分)

旅行前的准备 (25分)

2024-07-10 11:07| 来源: 网络整理| 查看: 265

LX同学想要游遍整个中国甚至全世界!所以这个国庆假期她计划去长沙玩。但是在她做旅行前的准备的时候,她收到了老师的作业,并且要求在国庆假期结束之前上交!LX同学非常的生气,告诉了你这个消息。你也觉得实在是太过分了,但是没有办法,只好帮助LX同学完成她的作业。

老师给了LX同学两个整数,分别是 x 和 y 。每次LX同学可以从中选择一个数 num ,把这个数变成 (num+2) mod p 或 (num∗2) mod p 或 (num∗num) mod p ,请问,最少需要多少次操作,能使这两个整数相等。 输入格式:

一行三个正整数 x,y,p(3≤p≤10​6​​,1≤x,y if (x.x x, y}); inq.insert({x, y}); while (!q.empty()) { node t = q.front(); int layer = t.layer; if (t.x == t.y) { cout q.push(t); inq.insert(t); } t.x = (x % p * x % p) % p, t.y = y; if (!inq.count(t)) { q.push(t); inq.insert(t); } t.x = x, t.y = (y % p + 2 % p) % p; if (!inq.count(t)) { q.push(t); inq.insert(t); } t.x = x, t.y = (y % p + y % p) % p; if (!inq.count(t)) { q.push(t); inq.insert(t); } t.x = x, t.y = (y % p * y % p) % p; if (!inq.count(t)) { q.push(t); inq.insert(t); } } } int main() { int x, y; cin >> x >> y >> p; bfs(x % p, y % p); return 0; }



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有