1. 程式人生 > >【同余】HDU 6108 小C的倍數問題

【同余】HDU 6108 小C的倍數問題

同余 pen display col 數學 include namespace http spl

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

【同余】HDU 6108 小C的倍數問題