HDOJ-1014 Uniform Generator

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=1014

Give the formula Seed (x+1) = [Seed (x) + STEP]% MOD

Seed is initially 0, giving step and mod values

Ask if seed can fetch all the values between 0~ (MOD-1)

Simple simulation

# include <stdio.h>int main () {int Step, Mod, I, Seed, Flag[100005];while (scanf ("%d%d", &step, &mod)! = EOF) { for (i = 0; I <= Mod-1; i++) flag[i] = 0; Seed = 0;do{flag[seed] = 1; Seed = (seed + Step)% Mod;} while (Seed! = 0); for (i = 0; I <= Mod-1, i++) if (flag[i] = 0) break;if (i <= Mod-1) printf ("%10d%10d Bad    choice\ N\n ", step, MoD); elseprintf ("%10d%10d    good choice\n\n ", step, MoD);} return 0;}

  

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.