A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, … shows the first 20 humble numbers.
Now given a humble number, please write a program to calculate the number of divisors about this humble number.For examle, 4 is a humble,and it have 3 divisors(1,2,4);12 have 6 divisors.
InputThe input consists of multiple test cases. Each test case consists of one humble number n,and n is in the range of 64-bits signed integer. Input is terminated by a value of zero for n.
OutputFor each test case, output its divisor number, one line per case.
Sample Input4
12
0Sample Output3
6
要了解题意是什么不是要求一共因数而是求2,3,5,7的倍数的乘积。
题解
#include<iostream>
using namespace std;
#define ll long long
int main()
{
ll n;
while (cin >> n)
{
if (n == 0)
break;
int a, b, c, d;
a = b = c = d = 1;
while (n != 1)
{
if (n % 2 == 0)
{
a++; n = n / 2;
}
if (n % 3 == 0)
{
b++, n = n / 3;
}
if (n % 5 == 0)
{
c++; n /= 5;
}
if (n % 7 == 0)
{
d++; n /= 7;
}
}
cout << a * b * c * d << endl;
}
return 0;
}
七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:“你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!”
人们纷纷来到告示前,都想知道谁才是自己的另一半.告示如下:
数字N的因子就是所有比N小又能被N整除的所有正整数,如12的因子有1,2,3,4,6.
你想知道你的另一半吗?
Input输入数据的第一行是一个数字T(1<=T<=500000),它表明测试数据的组数.然后是T组测试数据,每组测试数据只有一个数字N(1<=N<=500000).
Output对于每组测试数据,请输出一个代表输入数据N的另一半的编号.
Sample Input3
2
10
20Sample Output1
8
22
这个挺有意思的不用考虑超时一般都能过,我的题解别忘减去自己。
#include<iostream>
using namespace std;
const int maxn=500000+5;
#define ll long long
ll a[maxn];
int main()
{
ll m,n;
for(int i=1;i<=maxn;i++)
for(int j=1;i*j<=maxn;j++)
a[i*j]+=i;
while(cin>>n)
{
while(n--)
{
cin>>m;
cout<<a[m]-m<<endl;
}
}
return 0;
}
下周加油。