【2017"百度之星"程序设计大赛

【链接】http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=775&pid=1001


【题意】


在这里写题意

【题解】



abcd = a*p^3+b*p^2+c*p^1+d = a*(p^3-1)+b*(p^2-1)+c*(p-1)+a+b+c+d
则如果各位数上的和是m的倍数,且左边那一堆也是m的倍数的话,abcd就是m的倍数了;
且p^(x+1)-1=(p^x-1)*p+p-1
则如果p-1是m的倍数,p^2-1...都是m的倍数;
则整个abcd都是m的倍数.
所以只要是p-1的因子x就都可以了.
这样各位数的和只要是x的倍数,这个数就是x的倍数了.

【错的次数】


0

【反思】


在这了写反思

【代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x+1)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110;

int T,x;

int main(){
    //Open();
    //Close();
    ri(T);
    while (T--){
        int p;
        ri(p);
        int ans = 0;
        rep1(i,1,(int) sqrt(p-1))
            if ((p-1)%i==0){
                if (i == ((p-1)/i))
                    ans++;
                else
                    ans+=2;
            }
        oi(ans);
        puts("");
    }
    return 0;
}


原文地址:https://www.cnblogs.com/AWCXV/p/7626096.html