题目链接:https://vjudge.net/contest/373416#problem/F
Ivan has number bb. He is sorting through the numbers aa from 1 to 1018, and for every a writes [a,b]/a on blackboard. Here [a,b] stands for least common multiple of a and b. Ivan is very lazy, that’s why this task bored him soon. But he is interested in how many different numbers he would write on the board if he would finish the task. Help him to find the quantity of different numbers he would write on the board.
Input
The only line contains one integer — b (1≤b≤1010).
Output
Print one number — answer for the problem.
Input
1
Output
1
Input
2
Output
2
翻译:
给定一个b,a的范围为[1,1018],[a,b]表示lcm(a,b)。(a从1开始)。求[a,b]/a不同的个数。
分析:
b和a都是非常大的数,且时间复杂度为1000ms,必须为一层循环。
从a的范围入手:
- 若a>b,则lcm(a,b)/a的值都是固定的(都是b)。
- 考虑a的范围只用考虑小于b即可。
以根号b为分界点(root)
小于root的范围为b-。
大于root的范围为b+。
枚举1~root(i):
若b%i=0即b%b-=0。则b为b-的倍数,换句话说b-为b的因子。可以得出lcm(b,b-)=b。那么lcm(b,b-)/b-则等于b的另一个因子,这另一个因子一定在b+的范围内。
所以只用枚举1~root的数即可。
代码:
#include<cstdio>
#include<cstring>
#include<math.h>
#include<iostream>
#include<queue>
#include<stdlib.h>
#include<algorithm>
using namespace std;
typedef long long LL;
int main()
{
LL b;
scanf("%lld",&b);
LL root=sqrt(b);
LL res=0;
for(int i=1; i<=root; i++)
{
if(b%i==0)
res+=2;
}
if(root*root==b)
res-=1;
printf("%lld\n",res);
return 0;
}