题目地址:HDU 5373
题意:给你一个数n和操作次数t,每次操作将n的各位数之和求出来放在n的末尾形成新的n,问t次操作后得到的n能否够被11整除。
思路:就是简单的模拟一下乱搞。额,对于%11有一个性质,当一个数的奇数位之和与偶数位之和的差的绝对值能被11整除,那么该数就能够被11整除。
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef __int64 LL;
const int inf=0x3f3f3f3f;
const double pi= acos(-1.0);
const double esp=1e-7;
const int maxn=2*1e6+10;
LL k;
LL tail;
LL get(LL x)
{
LL cnt=1;
LL y=x;
while(x){
tail+=x%10;
x/=10;
cnt*=10;
}
k=(k*cnt+y)%11;
}
int main()
{
LL n,t;
int icase=1;
while(~scanf("%lld %lld",&n,&t)){
if(n==-1&&t==-1) break;
k=0,tail=0;
get(n);
while(t--)
get(tail);
if(!k) printf("Case #%d: Yes
",icase++);
else printf("Case #%d: No
",icase++);
}
return 0;
}