Codeforces Round #276 (Div. 2) A. Factory (number theory)

Source: Internet
Author: User
Tags cmath

This question can be performed in a brute force manner in the required way. If you do this for 1000000 times, you will not be able to perform the entire m operation, and you will never be able to perform the entire m operation (m cannot exceed 100000, the cycle is 1000000 times safer ). This method can be AC.

The following is an in-depth analysis of how many cycles can be used to determine the results: (a + B) % c = (a % c + B % c) % c, in this case, this question is actually 2 * a each time. Official answer:

Production will stops iff exists integerKLimit ≥ limit 0 suchA· 2KIs divisibleM. From this fact follows thatKMaximum will be aboutO(Log2 (M). So if we modeling some, for example, 20 days and production does not stop, then it will never stop and answer is "No". Otherwise answer is "Yes ".

# Include <iostream> # include <cstdio> # include <cstdlib> # include <cstring> # include <string> # include <cmath> # include <map> # include <set> # include <vector> # include <algorithm> # include <stack> # include <queue> # include <cctype> # include <sstream> using namespace std; # define pii pair <int, int> # define LL long intconst int eps = 1e-8; const int INF = 1000000000; const int maxn = 1000 + 5; int a, m; int main () {// freopen ("in8.txt", "r", stdin); // freopen ("out.txt", "w", stdout ); scanf ("% d", & a, & m); int w = 0; for (int I = 0; I <20; I ++) {if (a % m = 0) {w = 1; puts ("Yes"); break;} a % = m; a + = ;} if (w = 0) puts ("No"); // fclose (stdin); // fclose (stdout); return 0 ;}

If you do not want to do this, you can find the periodic rule. However, note that the cycle does not necessarily start with the first number. In fact, as long as the % m following has appeared before, so you don't have to calculate it any more. It must be the same in the future.

# Include <iostream> # include <cstdio> # include <cstdlib> # include <cstring> # include <string> # include <cmath> # include <map> # include <set> # include <vector> # include <algorithm> # include <stack> # include <queue> # include <cctype> # include <sstream> using namespace std; # define pii pair <int, int> # define LL long intconst int eps = 1e-8; const int INF = 1000000000; const int maxn = 1000 + 5; int a, m; set <int> s; int main () {cin> a> m; wh Ile (a % m! = 0) {if (s. find (a % m )! = S. end () {cout <"No" <endl; return 0;} s. insert (a % m); a + = (a % m);} cout <"Yes" <endl; return 0 ;}

 

Codeforces Round #276 (Div. 2) A. Factory (number theory)

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.