这题真的是触及到了我的知识盲区,写了一个16分的答案,看了答案(开长整型找不到结果的特殊判断)之后改成了18分,还是没有AC。终于,我仔细一看标准代码,发现这题不简单。

wa代码:

#include <stdio.h>
#include <memory.h>
#include <math.h>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <map>

#define I scanf
#define OL puts
#define O printf
#define F(a,b,c) for(a=b;a<c;a++)
#define FF(a,b) for(a=0;a<b;a++)
#define FG(a,b) for(a=b-1;a>=0;a--)
#define LEN 1010
#define MAX (1<<30)-1
#define V vector<int>

typedef long long ll;

using namespace std;



int main(){
    int n;
    n=6;
//    I("%lld",&n);
    int t=n,i;
    vector<int> ans;
    vector<int> cur;
    bool flag=0;
    for(i=2;i<=sqrt(n);i++){
        if(t%i==0){
            cur.push_back(i);
            t/=i;
            flag=1; 
        }else{
            if(flag){    //断了 
                t=n;
                if(cur.size()>ans.size()){// || (cur.size()>0&&ans.size()>0&& cur.size()==ans.size() && cur[0]<ans[0])
                    ans=cur;
                }
                cur.clear();
            }
            flag=0; 
        }
    }
    if(cur.size()>ans.size()){
        ans=cur;
    }
    int sz=ans.size();
    if(sz){
        O("%d\n",sz);
        FF(i,sz){
            O("%d",ans[i]);
            if(i!=sz-1) O("*");
        }    
    }else O("%d\n%d",1,n);

    return 0;
}
View Code

相关文章:

  • 2021-07-05
  • 2022-12-23
  • 2021-10-05
  • 2021-09-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-22
  • 2021-05-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案