SGU_pyj帶飛系列(DAY_1)

第一次刷SGU,當然,實力還差的很遠,畢竟這個是給OIer省選用的,沒事和pyj來一起艹。。。感覺自己還是有很多要學的

101,A+B,,,,Duang~

105 

F - Div 3
Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u

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;




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章