Test instructions: Chinese problem, directly ignore ...
Analysis: First talk about my ideas, I look at the first feeling is to find the law, if next to calculate, se years are not run out, Not to mention the time limit is 0.25s, how to find the law, I forget the first 10, respectively, is 8,1,1,3,1,1,4,1,1,3, then I think it should be 113114 cycle plus a first bit is 8, sure enough AC.
And then I looked at the puzzle seems to be calculated, because the number is very large and not high precision, it must be to find the law, assuming that N has K-bit, respectively, from right to left A1,a2...ak, first A1 (that is, bit) is certainly not 9 (because if it is 9, then n+1 0), so n+ 1 Everyone is A1+1,a2...ak, because n mod P (n) = 0, so n = S * A1 * A2 *...* ak,n+1 = T * (a1+1) * A2 * ... * ak, i.e.:
N+1-n = 1 = [t* (a1+1)-S*A1] * A2 * A3 *...* AK. So we can conclude that the A2,a3,...ai are 1. So A1 | N, (a1+1) | (n+1), ("|" Represents the integer, not bitwise, OR).
and A1 to consider 8 values (1-8).
A1 = 1 o'clock, it is obvious that it is possible;
A1 = 2 o'clock, the first one must be set (because it is even), just consider (a1+1) | (n+1), that is, 3 can be divisible n+1, first k-1 bit is 1, so long as the consideration of 3| (k-1+3) on OK;
A1 = 3 o'clock, a1+1 = 4, it is obvious that the suffix is 14 not divisible by 4, is not established;
A1 = 4 o'clock, ibid.;
A1 = 5 o'clock, a1+1 = 6, and judgment 3 is the same;
A1 = 6 o'clock, judging 7| (n+1), we conclude that only when the previous K-1 1 is a multiple of 6, 7| (N+1) is established;
A1 = 7 o'clock, 8 cannot be divisible by 118, not established;
A1 = 8 o'clock, ibid., not established.
The first one below is my AC code, and the other is the code of the puzzle.
The code is as follows:
#include <iostream>#include<string>#include<cstdio>using namespaceStd;typedefLong LongLL;intMain () {intN scanf"%d", &N); --N; if(!n) printf ("8\n"); Else if(n%6==0) printf ("4\n"); Else if(n%3==0) printf ("3\n"); Elseprintf"1\n"); return 0;}
Code:
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>using namespacestd;intMain () {intK; scanf ("%d", &k); if(k = =1) {printf ("8\n"); return 0; } intCNT =1; if(K-1) %3==0) {CNT+=2; if(K-1) %6==0) {CNT++; }} printf ("%d\n", CNT); return 0;}
SGU 169 Numbers (Law of Search)