Mathematical Field of Experiments (打表)

Mathematical Field of Experiments
time limit per test
2.0 s
memory limit per test
256 MB
input
standard input
output
standard output

Mathematician Michael is dreaming how he becomes a Minister of Education in Russia and tries his innovative experimental educational program in Maths in an elementary school. The main feature of this program is learning arithmetical operations in fields of integers modulo prime numbers instead of fields of real numbers. Impressed by his idea, Michael has started to write a Maths textbook for the 1st grade kids and is already preparing exercises to find a square root in modular arithmetic.

In each such exercise an integer x is given, and it's needed to find its square root modulo prime number p, which is also given. The correct answer for such task is an integer s, such that s·s and x have the same remainder after division by p. In other words, the number  has to leave no remainder after division by p. It must be said that the square root s doesn't exist for some numbers x.

To speedup the process of preparing tasks in this topic, Michael decided to write a program that finds square roots modulo given prime number p for all numbers x from 0 to , or tells that the corresponding square root doesn't exist.

Input

The first line contains a prime number p (2 ≤ p ≤ 106). A prime number has exactly two different divisors.

Output

Output p space-separated integers, the i-th of which must be equal to the square root of  modulo p. All numbers must be between 0 and . If some square root doesn't exist, output  - 1 instead of it, and if there are multiple square roots for some i, output any of them.

Examples
input
5
output
0 4 -1 -1 3
input
7
output
0 1 3 -1 5 -1 -1
Note

In the first sample: .


打表找了规律。。

没 n/2 个数对p取膜就会陷入循环。。

然后直接暴力。。

#include<stdio.h>
#include<string.h>
using namespace std;
#define ll long long
#define N 1000000
ll num[N+5];
int main()
{
    ll n;
    while(scanf("%lld",&n)==1)
    {
        int tmp=n/2;
        for(int i=0;i<n;i++)num[i]=-1;
        for(long long i=0;i<=tmp;i++)
        {
            long long m=(i*i)%n;
            if(m>N)
                continue;
            num[m]=i;
        }
        for(int i=0;i<n;i++)
        {
            if(i)
            printf(" %lld",num[i]);
            else printf("%lld",num[i]);
        }
        printf("\n");
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值