您的位置:首页 > 其它

sgu105: Div 3

2015-06-12 08:43 537 查看
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 <= 2147483647

打表找规律就出来了

#include <cstdio>
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int n, ans;
    scanf("%d", &n);
    switch(n % 3) {
        case 0: ans = 2; break;
        case 1: ans = 0; break;
        case 2: ans = 1; break;
    }
    ans += (n-1) / 3 * 2;
    printf("%d\n", ans);

    #ifndef ONLINE_JUDGE
    fclose(stdin);
    fclose(stdout);
    #endif
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: