组队赛-15

C题,找规律

 

在最小循环节里统计不同数的个数就行

#include <iostream>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
const int N=1e7+10;
bool st[N];
signed main()
{
    int p;
    ll n;
    scanf("%d%lld",&p,&n);
    st[0]=true;
    ll ans=1;
    long long int sum=0;
    if (p%2)
    {
        for (int i=0; i<n; i++)
        {
            sum+=(i+1);
            if (!st[sum%p])
            {
                ans++;
                st[sum%p]=true;
            }
            if ((i+1)==p)break;
        }
    }
    else if (p%2==0)
    {
        for (int i=0; i<n; i++)
        {
            sum+=(i+1);
            if (!st[sum%p])
            {
                ans++;
                st[sum%p]=true;
            }
            if ((i+1)==p*2)break;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

 

posted @ 2022-05-20 01:02  好腻友Π  阅读(24)  评论(0)    收藏  举报