第一次刷SGU,當然,實力還差的很遠,畢竟這個是給OIer省選用的,沒事和pyj來一起艹。。。感覺自己還是有很多要學的
101,A+B,,,,Duang~
105
Description
There is sequence 1, 12, 123, 1234, ..., 12345678910, ... . Given first N elements of that sequence. You must determine amount of numbers in it that are divisible by 3.
Input
Input contains N (1<=N<=231 - 1).
Output
Write answer to the output.
Sample Input
4
Sample Output
2
解題思路:
這道題還蠻有點意思,感覺會拿while去跑每一位,但是沒這麼做,感覺這樣做就是多餘的,只要從1,12,123,1234,12345,123456,統計出這些數字對於mod3的結果,
爲100100,,,,所以規律就出來了,
cin>>n;
long long ans = 0;
if ( n%3==0 )
{
ans = n/3*2;
}
else
{
ans = n/3*2+n%3-1;
}
cout<<ans<<endl;