标签:class memset namespace 边界条件 typedef getc getchar stream read
#include<map> #include<queue> #include<time.h> #include<limits.h> #include<cmath> #include<ostream> #include<iterator> #include<set> #include<stack> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define rep_1(i,m,n) for(int i=m;i<=n;i++) #define mem(st) memset(st,0,sizeof st) inline int read() { int num=0, w=0; char ch=0; while (!isdigit(ch)) { w|=ch==‘-‘; ch = getchar(); } while (isdigit(ch)) { num = (num<<3) + (num<<1) + (ch^48); ch = getchar(); } return w? -num: num; } typedef long long ll; typedef pair<int,int> pii; typedef unsigned long long ull; typedef pair<double,double> pdd; const int inf = 0x3f3f3f3f; int n,ans=inf; void dfs(int dep,int num) { if(!num) { ans=min(ans,dep);//边界条件 return ; } num--;//把式子里面的1减掉 for(int i=2; i<=9; i++) //枚举k if(!(num%i)) //判断整除 dfs(dep+1,num/i); } void solve() { cin>>n; for(int i=1; i<=sqrt(n); i++) if(!(n%i)) { if(n/i!=n) dfs(0,i);//n/(n/i)=i if(i!=n) dfs(0,n/i);//n/i } if(ans!=inf) cout<<ans<<endl;//判断能否到达 else cout<<-1<<endl; } int main() { int t=1; while(t--) solve(); return 0; }
标签:class memset namespace 边界条件 typedef getc getchar stream read
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/13230464.html