BZOJ1406[AHOI2007] Cipher Box

Source: Internet
Author: User

BZOJ1406[AHOI2007] Cipher Box

Test instructions

An integer that outputs 1 to n-1, and modulo n equals 1

Exercises

Set the number x, X+1 (x-1) =n*k, set n1*n2 equals K, (x+1)%n1==0, (x-1)%n2==0, so N1, N2 are the factor of N, and a ≤sqrt (n), a ≥ (sqrt (n)). It is said that the number within the int is no more than 30 factors, so the factor of all ≥SQRT (n) can be calculated first, and then for each factor, to find out the multiple of the factor of all

Code:

1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <cmath>5 #defineInc (I,J,K) for (int i=j;i<=k;i++)6 #defineMAXN 1007 using namespacestd;8 9 intyss,ys[maxn],st[maxn* the],sts;Ten intMain () { One     intN scanf"%d", &n); Inc (I,1,(int) sqrt (n))if(n%i==0) ys[++yss]=n/i; st[sts=1]=1; AInc (I,1, Yss) { -          for(intj=ys[i];j<=n;j+=Ys[i]) { -             if(J-2)% (n/ys[i]) = =0) st[++sts]=j-1; the             if(j<n&& (j+2)% (n/ys[i]) = =0) st[++sts]=j+1; -         } -     } -     if(sts==0|| n==1) printf ("None");Else{ +Sort (st+1, st+1+sts);intM=unique (st+1, st+1+sts)-st-1; Inc (I,1, m) printf ("%d\n", St[i]); -     } +     return 0; A}

20160603

BZOJ1406[AHOI2007] Cipher Box

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.