ural 1110 Power



1110. Power

Time limit: 0.5 second

Memory limit: 64 MB

You are given the whole numbers N, M and
Y. Write a program that will find all whole numbers X in the interval [0,
M ? 1] such that XN mod
M = Y.

Input

The input contains a single line with N,
M and Y (0 < N < 999, 1 < M < 999, 0 < Y < 999) separated with one space.

Output

Output all numbers X separated with space on one line. The numbers must be written in ascending order. If no such numbers exist then output ?1.

Sample

input output
2 6 4
2 4

Problem Source: Bulgarian National Olympiad Day #1

Tags: (

show tags for all problems
)

题意:是否存在x,使得x的n次方%m等于y,存在的话输出所有的x。不存在输出负一。

水题,跑个快速幂。

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int m;
int fast_mi(int a,int k)
{
    int res=1;
    while(k)
    {
        if(k&1)
            res=res*a%m;
        a=a*a%m;
        k>>=1;
    }
    return res;
}
int main()
{
    int n,y,i;
    int a[1000];
    while(cin>>n>>m>>y)
    {
        int flag=0;
        memset(a,0,sizeof(a));
        int len=0;
        for(i=0; i<=m-1; i++)
        {
            if(fast_mi(i,n)%m==y)
            {
                flag=1;
                a[len++]=i;
            }
        }
        if(flag)
        {
            for(i=0; i<len; i++)
            {
                if(!i)
                    cout<<a[i];
                else
                    cout<<" "<<a[i];
            }
            cout<<endl;
        }
        else
            cout<<-1<<endl;
    }
    return 0;
}

时间: 2024-10-14 02:29:07

ural 1110 Power的相关文章

URAL 1723. Sandro&#39;s Book

1723. Sandro's Book Time limit: 0.5 second Memory limit: 64 MB It's been quite a number of years since Lich Sandro retired. Sometimes in the evenings, when he feels especially lonely, he takes a book that was presented to him by his student magicians

URAL 1728. Curse on Team.GOV(STL set)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1728 1728. Curse on Team.GOV Time limit: 0.5 second Memory limit: 64 MB All the names in this problem are fictitious; the coincidences are accidental. Long ago there was the Alarm team at the Ural Sta

【计算几何】URAL - 2101 - Knight&#39;s Shield

Little Peter Ivanov likes to play knights. Or musketeers. Or samurai. It depends on his mood. For parents, it is still always looks like "he again found a stick and peels the trees." They cannot understand that it is a sword. Or epee. Or katana.

ural 1250. Sea Burial

1250. Sea Burial Time limit: 1.0 secondMemory limit: 64 MB There is Archipelago in the middle of a shoreless ocean. An ancient tribe of cannibals lives there. Shamans of this race have been communicating with gods and admonishing people for ages. The

ural 2062 Ambitious Experiment

2062. Ambitious Experiment Time limit: 3.0 secondMemory limit: 128 MB During several decades, scientists from planet Nibiru are working to create an engine that would allow spacecrafts to fall into hyperspace and move there with superluminal velocity

Cache memory power reduction techniques

Methods and apparatus to provide for power consumption reduction in memories (such as cache memories) are described. In one embodiment, a virtual tag is used to determine whether to access a cache way. The virtual tag access and comparison may be per

URAL 1025. Democracy in Danger (贪心)

1025. Democracy in Danger Time limit: 1.0 second Memory limit: 64 MB Background In one of the countries of Caribbean basin all decisions were accepted by the simple majority of votes at the general meeting of citizens (fortunately, there were no lots

ADC Power Supplies

http://www.planetanalog.com/author.asp?section_id=3041&doc_id=563055 Jonathan Harris, Product Applications Engineer, Analog Devices, 6/2/2014 As I thought about where to go with the next blog, I looked over the comments and questions from my previous

(校赛)URAL 1998 The old Padawan

Luke Skywalker is having exhausting practice at a God-forsaken planet Dagoba. One of his main difficulties is navigating cumbersome objects using the Power. Luke's task is to hold several stones in the air simultaneously. It takes complete concentrat