http://www.lightoj.com/volume_showproblem.php?problem=1136
Start to solve two times with the same, calculate a will find a lot of solutions. --> instead of parsing the sequence structure.
Analysis found:
A number of numbers that consist of three consecutive integers together and bound to be divisible by 3. (X+x+1+x+2=3x+3=3 (x+1))
Thus there are:
1. The number of 3rd K in the title must be divisible by three.
2. The 3rd K + 1 number in the title, its 2nd number to the last number of the sum must be divisible by 3, plus the first number, that is 1, can not be 3 whole.
3. The 3rd K + 2 number in the title, the sum of the 3rd number to the last digit must be divisible by 3, plus the first to second number, which is 1 + 2 = 3, and divisible by 3.
So the 1~k can be divisible by 3 with 2k/3+ (k%3==2?1:0).
Complete code:
01./*0.008s,1088kb*/
.
#include <cstdio>
04.typedef unsigned int ll;
06.ll Calc (ll k)
07.{
Return K/3 * 2 + (k 3 = 2 1:0);
.
11.int Main ()
12.{ int T, cas = 0; ll A, B; scanf ("%d", &t);
While (t--)
. { scanf ("%u%u", &a, &b); printf ("Case%d:%u\n", ++cas, Calc (b)-Calc (A-1));
. return 0;
22.}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/