Hdoj 1014 Uniform Generator

Source: Internet
Author: User
Tags greatest common divisor

Title: Click to open link

Analysis: The problem requires a uniform generation of random numbers, there are two ways: 1 to the number of the generation to mark 2 to generate a random number of step and mod greatest common divisor not more than 1

Code One:

#include <stdio.h> #include <string.h>int a1[100010];int main () {int step,mod;while (~scanf ("%d%d",& STEP,&MOD) {int I;int k=0;memset (a1,0,sizeof (A1)), for (i=1;i<=mod-1;i++) {   k= (k+step)%mod;   if (A1[k]) break   ;   a1[k]++;    } if (i!=mod) printf ("%10d%10d bad    choice\n", step,mod); elseprintf ("%10d%10d    good choice\n", step,mod); printf ("\ n");} return 0;}


Code two:

#include <stdio.h>int main () {int s,m;while (~scanf ("%d%d", &s,&m)) {int i,k=0;for (i=1;i<=m;i++) {if (s %i==0&&m%i==0&i>1) k=1;} if (k) printf ("%10d%10d bad    choice\n", s,m), elseprintf ("%10d%10d    good choice\n", s,m);p rintf ("\ n");} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Hdoj 1014 Uniform Generator

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.