ZCMU-1543-numbers

1543: Numbers

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值