Returns the remainder of a large number.

Source: Internet
Author: User

Since learning ACM, yefeng has told people that he can quickly determine whether a positive integer number is a prime number. Later, we guess he only knows how to determine the number within 10 ^ 18. So I want to ask him with a very large number. Of course, for a very large number of yefeng, it cannot be calculated in a short time. Fortunately, yefeng learned the Prime Number Theorem and knew that the larger the number, the lower the probability of the number being a prime number. So he intentionally told everyone a number and attached a sentence, this number is a factor for the number you give, so the number you give is a sum. Smart, can you come up with a way to tell the lie that exposes yefeng?

Several groups of test data, each group of test data in two rows, the first row is the number of yefeng to determine a (10 ^ 20 <= A <= 10 ^ 1000 ), the second row is yefeng's guess factor B (2 <= B <= 9999 ). The data guarantee integer does not have a leading 0.

If B is a factor of A, yes is output; otherwise, the remainder is output.

546112345612312369851232 2 145645612123123154654319 2 output yes1

# Include <stdio. h> # include <string. h> // (A * B) % C = (a % C) * (B % C) % C; int row (int K, int N) // (a + B) % C = (a % C + B % C) % C for multiple multiplication, the addition is similar. {Int F = 1, R = 1, I; for (I = 0; I <k/6; I ++) // downgrade, drop six bits each time (because the six-digit number can be reduced) f * = 1000000% N; for (I = 0; I <K % 6; I ++) R * = 10; return f * (R % N) % N;} int main () {char a [1001]; int N, K, K1, C, B; while (scanf ("% s", )! = EOF) {int sum = 0; scanf ("% d", & N); k1 = k = strlen (a)-1; for (INT I = 0; I <= K; I ++) {c = (a [I]-48) % N; B = row (K1 --, N ); sum + = (C * B) % N;} If (sum % N = 0) printf ("Yes \ n"); else printf ("% d \ n ", sum % N) ;}return 0 ;}

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.