清北学堂模拟赛d4t4 a

 

分析:感觉和dp的状态转移方式有点类似,对于一个数,你不能看有多少个状态能转移到它,你要看它能转移到多少个状态,相当于刷表法和填表法的区别,对于这道题也是一样,我们不能看有多少个数是x的倍数,而是每次将x的因数ans++,然后询问直接输出就可以了.

#include <bits/stdc++.h>

using namespace std;

int n,a[40010],ans,t;

void solve(int x)
{
    for (int i = 1; i * i <= x; i++)
    {
        if (x % i == 0)
        {
            if (i * i != x)
            {
                a[i]++;
                a[x / i]++;
            }
            else
                a[i]++;
        }
    }
}

int main()
{
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    scanf("%d",&n);
    t = n;
    while (n--)
    {
        int opt,x;
        scanf("%d%d",&opt,&x);
        if (opt == 1)
            solve(x);
        else
        {
            if (n == t)
                ans = a[x];
            else
                ans ^= a[x];
        }
    }
    printf("%d\n",ans);

    return 0;
}

 

posted @ 2017-10-09 21:49  zbtrs  阅读(212)  评论(0编辑  收藏  举报