Brian Warehouse

Some birds aren`t meant to be caged, their feathers are just too bright... ...
posts - 40, comments - 16, trackbacks - 0, articles - 1

SGU 105 Div 3

Posted on 2010-08-17 13:26 Brian 阅读(259) 评论(0)  编辑 收藏 引用 所属分类: SGU

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. (找出这个数列1-N号元素中能被3整除的有多少个)

Input

Input contains N (1<=N<=231 - 1).

一个数乘以10以后,模3后结果不变,第2,5,8,11,14,17........项满足要求

#include <stdio.h>
int main()
{
    
int N;
    scanf(
"%d",&N);
    N
--;
    printf(
"%d\n", N-(N/3));
    
return 0;
}  
// 0K  0MS

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理