2012年10月18日 星期四

SGU 105 Div 3

If a number is divisible by 3, than it's sum of digit is divisible by 3If it's sum of digit is divisible by 3, than the number is divisible by 3

And Sn's sum of digit will be n*(n-1)/2

貌似便是如此而已

//By momo
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n;
    scanf("%d", &n);
    int x = (n / 3);
    if(n % 3 == 0) printf("%d\n", 2*x);
    if(n % 3 == 1) printf("%d\n", 2*x);
    if(n % 3 == 2) printf("%d\n", 2*x+1);
}

沒有留言:

張貼留言