Numbers

1543: Numbers
时间限制: 1 Sec  内存限制: 128 MB
提交: 445  解决: 106
[提交][状态][讨论版]
题目描述
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.


输入
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).


输出
For each test case, print the number of positive integers D that satisfies the rules.


样例输入
2
1
10
样例输出
1
2
提示

来源


心得:直接将n变为二进制并用数组存储起来

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int a[1001];
int is_f(LL p)
{
	LL i=0;
	while(p)
	{
		LL tp=p%2;
		if(a[i]==tp) return 1;
		p/=2; i++;
	}
	return 0;
}
int main(void)
{
	int t;
	LL p,num;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%lld",&p); 
		LL tp=p,i=0;
		while(tp)
		{
			a[i]=tp%2;
			i++;
			tp/=2;
		}
		num=0;
		for(i=1;i*i<=p;i++)
			if(p%i==0)
			{
				if(is_f(i)) num++;
				if(is_f(p/i)&&(i*i!=p)) num++;
		    }
		printf("%lld\n",num);
		memset(a,0,sizeof(a));
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值