The planet Venus is known for its toxic atmosphere and infernal temperatures, where apparently any civilization would be unable to live and thrive. However, records of an ancient civilization (the "Venirics") that inhabited Venus millions of years ago have been recently detected on this planet.
Faced with this surprising discovery, the Union of Solar Planets (USP) decided to send to this planet the only specialist capable of retrieving these records and revealing more details about the history of the Venutian civilization: the space archaeologist Otávio.
In his extensive research, Otávio discovered surprising facts about the generations of Venirics:
The only intact record that Otávio found about the size of the historical Venirics population was its total number (i.e., the sum of the sizes of all populations from generation 0 to generation m), but he was unable to deduce anything about the values of a, r, and m, and therefore asked for help from Marcelo, the space computer scientist.
Marcelo was also unable to deduce the values of a, r, and m from n, as he wisely noticed that different values of these parameters could have led to the same value of n. The only thing he knows is that there are not many possibilities for the sizes of the generations given n, and he wishes to determine how many there are.
Since returning from the toxicity of Venus, however, he can no longer type, and so he asked you to write a program that answers the question for him.
Input
A single integer n (1≤n≤109), the total historical population of the Venirics.
Input
A single integer n (1≤n≤109), the total historical population of the Venirics.
Examples
input
7
output
3
input
1000000000
output
101
#include<iostream>
#include<map>
#include<cmath>
#define ll long long
using namespace std;
int main(){
ll n;
cin >> n;
ll ans = 0;
//求m = 2时的情况,即n除了1以外的因数个数
if(n >= 2){
for(int i = 2; i*i <= n ;++i){
if(i * i == n){
ans += 1;
continue;
}
if(n % i == 0)
{
ans += 2;
}
}
ans ++ ;
}
//枚举 r,m
if(n >= 7){
for(ll r = 2 ; r*r <= n ; ++r){
ll gcd = 1 + r ;
for(ll m = 2; m <= n ; ++m){
gcd = gcd * r + 1;
if(gcd > n)break;
if( gcd != 0 && n % gcd == 0) {
++ans;
}
}
}
}
// m = 0 时只有一种情况,答案加上1.
cout << ans + 1;
return 0;
}
我的代码输入1000000000,输出102,找不到原因