【同余】HDU 6108 小C的倍数问题
2024-10-21 04:10:37
http://acm.hdu.edu.cn/showproblem.php?pid=6108
【题意】
给定进制P,求有多少个B满足P进制下,一个正整数是B的倍数的充分必要条件是每一位加起来的和是B的倍数。
【思路】
当时记起了离散数学课上学过为啥10进制下是3和9(因为10,3,9关于1同余),所以想到答案是n-1的因子个数
【AC】
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath> using namespace std; int n; int factor(int x)
{
int cnt=;
for(int i=;i*i<=x;i++)
{
if(x%i==)
{
if(i*i!=x)
{
cnt+=;
}
else
{
cnt+=;
}
}
}
return cnt;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
n-=;
int ans=factor(n);
printf("%d\n",ans);
}
return ;
}
最新文章
- css工具收集
- (Collection)350. Intersection of Two Arrays II
- Opencv CamShift+Kalman目标跟踪
- mysql一个事务中有DDL语句的binlog情况
- css基本知识
- Android之ORMLite实现数据持久化的简单使用
- oracle 导入导出数据
- mysql:1153 Got a packet bigger than ‘max_allowed_packet’ bytes的解决方法
- American tour(If you have a chance)
- VC获取精确时间的做法
- HTML5线性图表 图表数据区域可着色
- libev实现分析
- iOS特性
- Python内置函数(26)——globals
- day 42 mycql 查询操作,重点中的重点
- FFT是个啥?
- sklearn linear_model,svm,tree,naive bayes,ensemble
- Django:视图views(一)
- 校园社交网站app
- 【Spring】Spring之事务处理