Codeforces 604D "Discrete mathematical permutation group"

Source: Internet
Author: User

Test instructions

Give you an equation, the equation is too perverted to fight, give you a p a k,p guarantee is a prime number greater than or equal to 3, and K guarantees an integer between 0~p-1. The definition field of the corresponding function is required to be a subset of 0~p-1 in the 0~p-1 domain, so how many ...

Analysis:

"Today, just vaguely listened to the festival set theory, doing to find it seems to be a cyclic group or what = ="

When k=0, it is not difficult to find f (0) = 0, any other.

K=1, f (0) =f (0) mod p, found in addition to any other accidental f (0) is also arbitrary.

When k>=2, find a rule ...

It is not difficult to find out if k=2, then f (2) According to F (1), F (4) According to F (2) ... And so on, until after the MoD operation becomes 1 again ...

So the values of many groups vary according to the value of one of the functions ... So I found a certain rule (which should be proved)

The law is this, found that <k> (the symbol of the interpretation of discrete mathematics = =) is the order of the definition of the domain (this should be deduced from a famous theorem, the cock silk just found the law) ...

OK, finally the problem becomes a regular problem (the dregs pain Pain)

In addition to 0, the definition field can be divided into a W group, each with a <k> order number. The rest of the matter is to arrange a combination, write a quick power solution ...

Reflection:

This problem reflects my analysis of this slag is not comprehensive, although 1A but after the discovery of a place to verify that they have neglected ...

Code:

#include <stdio.h>intMain () {intp,k; intn=1e9+7; scanf ("%d%d",&p,&k); if(k==0)    {        Long LongTmp=p,r=1; P--;  while(p) {if(p&1) {R=r*tmp%N; } tmp=tmp*tmp%N; P>>=1; } printf ("%i64d\n", R); }    Else if(k==1)    {        Long LongTmp=p,r=1;  while(p) {if(p&1) {R=r*tmp%N; } tmp=tmp*tmp%N; P>>=1; } printf ("%i64d\n", R); }    Else    {        Long Longtmp=1; Long Longans;  for(intI=1;; i++) {tmp= (tmp*k)%p; if(tmp==1) {ans=i;  Break; }        }        Long LongR=1; TMP=p; P= (P-1)/ans;  while(p) {if(p&1) {R=r*tmp%N; } tmp=tmp*tmp%N; P>>=1; } printf ("%i64d\n", R); }}

Codeforces 604D "Discrete mathematical permutation group"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.