/ Vijos / 讨论 / 问答 /

关于1310

请问1310数据是确保正确么?0,2,9三个点是不是有问题啊

1 条评论

  • @ 2016-03-20 05:44:51

    没有问题。

    • @ 2016-03-22 09:17:06

      真的没错么

    • @ 2016-03-22 09:18:18

      #include<stdio.h>
      #include<stdlib.h>
      #include<string.h>
      #include<math.h>
      int sushu[10000];
      int kp=1;
      int m,t,k,p;
      int a[1000];
      double min(0);
      void set(){
      memset(sushu,0,sizeof(sushu));
      sushu[1]=2;
      for (int i=3;i<=65536;i++)
      {
      int mark=1;
      for (int j=1;((j<=kp)&&((sushu[j]*sushu[j])<=i));j++)
      {
      if (i%sushu[j]==0)
      {
      mark=0;
      break;
      }
      }
      if (mark==1)
      {
      kp++;
      sushu[kp]=i;
      }
      }
      }
      int ans[1000];
      void search(int t)
      {
      for (int j=1;j<t;j++)
      {
      double b=min;
      b=min-(a[t]-1)*log(sushu[t]);
      b=b+(a[t]-1)*a[j]*log(sushu[j]);
      if (min>b)
      {
      int c=a[t];
      min=b;
      a[j]=a[j]*a[t];
      a[t]=0;
      for (int l=1;l<=k;l++) ans[l]=a[l];
      search(t-1);
      a[t]=c;
      a[j]=a[j]/c;
      }else return;
      }
      return;
      }
      int main(){
      set();
      int n;
      scanf("%d",&n);
      for (int i=1;i<=n;i++)
      {
      scanf("%d",&m);
      t=m;
      k=0;
      p=1;
      memset(a,0,sizeof(a));
      for (;t>0&&t>=sushu[p];)
      {
      if (t%sushu[p]==0)
      {
      k++;
      a[k]=sushu[p];
      t=t/sushu[p];
      }
      else
      p++;

      }
      for (int j=1;j*2<=k;j++)
      {
      int d=a[j];
      a[j]=a[k-j+1];
      a[k-j+1]=d;
      }
      min=0;
      for (int j=1;j<=k;j++) ans[j]=a[j];
      for (int j=1;j<=k;j++)
      min+=(a[j]-1)*log(sushu[j]);
      search(k);
      for (int j=1;j<=k;j++)
      {
      if (ans[j]!=0)
      {
      if (j!=1) printf("*");
      if (ans[j]==2) printf("%d",sushu[j]);
      else printf("%d^%d",sushu[j],ans[j]-1);
      }
      }
      printf("\n");
      }
      }

  • 1