SGU105 Div 3

版权声明:希望有人转(^_^) https://blog.csdn.net/Sunshine_cfbsl/article/details/52693396

水题。。。
题目大意:
给出如下序列:
1, 12, 123, 1234, 12345, 123456, 1234567, 12345678, 123456789, 12345678910, 1234567891011…
求出前n (1n2311) 个数中,三的倍数有几个。

直接上代码:

/*
ID: Sunshine_cfbsl
LANG: C++
*/
#include<cstdio>
#include<algorithm>
using namespace std;

int main() {
    int n, r, ans;
    scanf("%d", &n);
    ans = (n/3)*2;
    r = n%3;
    if(r == 2) ans++;
    printf("%d\n", ans);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Sunshine_cfbsl/article/details/52693396
今日推荐