1. 程式人生 > >Division Game UVA - 11859 Nim

Division Game UVA - 11859 Nim

Code:

#include<cstdio>
#include<algorithm>
using namespace std;
#define maxn 10005

int nums[maxn], prime[maxn], cnt, vis[maxn];
int main(){
    //freopen("input.in","r",stdin);
    vis[1]=1;
    for(int i=2;i<maxn;++i){
        if(!vis[i]) prime[++cnt]=i, vis[i]=i;
        for(int j=1;j<=cnt&&prime[j]*i<maxn;++j) {
            vis[prime[j]*i]=prime[j];
            if(i%prime[j]==0) break;
        }
        int x=0,y=i;
        while(y>1){
            while(y%vis[y]==0 && y>1){
                if(vis[y]!=1) ++x;
                y/=vis[y];
             
            }
        }
        nums[i]=x;
    }

    int T; scanf("%d",&T);
    for(int cas=1;cas<=T;++cas){
        int n,m,ans=0;
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;++i){
            int sumv=0;
            for(int j=1;j<=m;++j) {
                int a; 
                scanf("%d",&a);
                sumv+=nums[a];
            }
            ans^=sumv;
        }
        if(ans==0) printf("Case #%d: NO\n",cas);
        else printf("Case #%d: YES\n",cas);
    }
    return 0;
}