ZCMU-1543-numbers
来源:互联网 发布:淘宝上的旗舰店可信吗 编辑:程序博客网 时间:2024/06/06 08:43
1543: Numbers
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 323 Solved: 69
[Submit][Status][Web Board]
Description
DongDong is fond of numbers, and he has a positive integer P. Meanwhile, there is a rule that is:
A positive integer D that satisfies the following rules:
1. D is one of the factors of P
2. D and P have a same bit at least under the binary system.
So DongDong wants to know how many positive integers D there are.
Input
The first line contains a positive integer T (T<=1000), which means the number of test cases. Then comes T lines, each line contains a positive integer P (1<=P<=1000000000).
Output
For each test case, print the number of positive integers D that satisfies the rules.
Sample Input
2
1
10
Sample Output
1
2
【解析】
此题要求统计你n的因子当中有几个在二进制位当中的只要有一位数相等的就行。让你输出一共有几个,这个小细节我们就要注意了。因为p取最大值时很大...
#include<cstdio>using namespace std;int a[100];int check(int n)//判断二进制位当中有没有相等的{ int r; for(int i=0;n!=0;i++,n=n>>1)//n右移一位相当于n/2 { r=n&1;//如果n的二进制位当中是1的则还是1如果是0的则变成0了 if(r==a[i]) return 1; } return 0;}int main(){ int t,i; long long n,m,count; scanf("%d",&t); while(t--) { count=0; scanf("%lld",&n); m=n; for(i=0;n!=0;i++) { a[i]=n&1;//把n的二进制位写入 n=n>>1; } for(i=1;i*i<=m;i++) { if(m%i==0) { if(check(i)) count++;//这个是检测因子的好办法了省时间 if(check(m/i)&&(i*i!=m)) count++; } } printf("%lld\n",count); } return 0;}
0 0
- ZCMU-1543-numbers
- zcmu--1570: Palindromic Numbers
- ZCMU-1379-The Black Hole of Numbers
- zcmu-1657
- zcmu-1685
- ZCMU----1776
- ZCMU----1777
- ZCMU----1778
- ZCMU----1779
- ZCMU-1731
- ZCMU-1658
- ZCMU-1654
- ZCMU-1132
- ZCMU-1037
- ZCMU-1415
- ZCMU-1036
- ZCMU-1723
- ZCMU-1608
- JAVA解析PDF、WORD、EXCEL文档
- Linux 各目录的作用
- jQuery eq(index)选择器
- 启动IntelliJ IDEA 2016报错:cannot start under Java 1.7 : Java 1.8 or later is required
- springboot与mybatis整合
- ZCMU-1543-numbers
- web.xml简单配置
- Java之Semaphore
- jni小示例
- Android源码
- ERROR: x265 not found using pkg-config
- kmalloc、vmalloc、malloc的区别
- python模块-decimal小数精度处理-学习笔记28
- 深入分析Java线程中断机制