标签:time limit sqrt 相等 enter main map namespace 等于
12
8
1 #include <bits/stdc++.h> 2 using namespace std; 3 map<int,int> mp; 4 int fun(int n){ 5 if(mp[n]) return mp[n];//如果这个数已经计算过了,可以直接返回 6 if(n==1) return 1; 7 int sum=1;//个数为1 8 for(int i=2;i<=sqrt(n);i++){// 等于 sqrt(n); 9 if(n%i==0){//需成为 因子 才可以继续计算 10 sum+=fun(i); 11 if(i!=n/i) sum+=fun(n/i);//若i== n/i 那么 只算一次,不相等,两边都算 12 } 13 14 } 15 mp[n]=sum;//跟新mp[n] 16 return sum; 17 } 18 int main() 19 { 20 int n; 21 cin>>n; 22 cout<<fun(n)<<endl; 23 return 0; 24 }
标签:time limit sqrt 相等 enter main map namespace 等于
原文地址:https://www.cnblogs.com/NirobertEinteson/p/11930054.html