百度之星初賽-(A) A小C的倍數問題

根據小學數學的知識,我們知道一個正整數x是3的倍數的條件是x每一位加起來的和是3的倍數。反之,如果一個數每一位加起來是3的倍數,則這個數肯定是3的倍數。

現在給定進制P,求有多少個B滿足P進制下,一個正整數是B的倍數的充分必要條件是每一位加起來的和是B的倍數。

Input

第一行一個正整數T表示數據組數(1<=T<=20)。

接下來T行,每行一個正整數P(2 < P < 1e9),表示一組詢問。

Output

對於每組數據輸出一行,每一行一個數表示答案。

Sample Input
1
10
規律是(n-1)的因子個數是多少個。直接敲代碼即可。

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#define siz 1005
#define LL long long
#include <vector>
#include <string.h>
using namespace std;
int n,m,k;
int has[siz];
vector<int>vec[siz];
void _Init(){
    memset(has,0,sizeof(has));
    for(int i=0;i<siz;i++){
        vec[i].clear();
    }
}
int p;
void solve(){
    int x = p-1;
    int ans = 2;
    //cout<<x<<endl;
    for(int i=2;i<=sqrt(x)+1;i++){
        if(x%i==0){
            if(i==sqrt(x) && x/i==i){
                 ++ans;
            }
            else ans+=2;
    }}
    cout<<ans<<endl;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--){
       // int p;
        scanf("%d",&p);

       solve();
    }
    return 0;
}






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章