【同余】HDU 6108 小C的倍数问题

http://acm.hdu.edu.cn/showproblem.php?pid=6108

【题意】

给定进制P,求有多少个B满足P进制下,一个正整数是B的倍数的充分必要条件是每一位加起来的和是B的倍数。

【思路】

当时记起了离散数学课上学过为啥10进制下是3和9(因为10,3,9关于1同余),所以想到答案是n-1的因子个数

【AC】

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<string>
 5 #include<algorithm>
 6 #include<cmath>
 7 
 8 using namespace std;
 9 
10 int n;
11 
12 int factor(int x)
13 {
14     int cnt=0;
15     for(int i=1;i*i<=x;i++)
16     {
17         if(x%i==0)
18         {
19             if(i*i!=x) 
20             {
21                 cnt+=2;
22             }
23             else
24             {
25                 cnt+=1;
26             }
27         }
28     }
29     return cnt;
30 }
31 int main()
32 {
33     int T;
34     scanf("%d",&T);
35     while(T--)
36     {
37         scanf("%d",&n);
38         n-=1;
39         int ans=factor(n);
40         printf("%d\n",ans);
41     }    
42     return 0;
43 }
View Code

 

posted @ 2017-08-13 18:46  shulin15  阅读(220)  评论(0编辑  收藏  举报