#include<iostream>
#include<math.h>
using namespace std;
struct stuOneF
{
int nFact;
int nPow;
};
struct stuAllFs
{
int nFact[50];
int nPow[50];
int nCount;
};
stuAllFs stuGetAll(int nInN);
void vOutput(stuAllFs stuAns);
stuOneF stuGetOne(int & nInN,int nDiv);
int main()
{
int nCase;
int i;
stuAllFs stuAns;
int nInNum;
cin >> nCase;
for(i=1;i<=nCase;i++)
{
cin >> nInNum;
stuAns=stuGetAll(nInNum);
vOutput(stuAns);
}
return 0;
}
stuAllFs stuGetAll(int nInN)
{
stuAllFs stuRet;
stuOneF stuAl;
int i,j;
int nUpto;
if(nInN<1)
{
stuRet.nCount=0;
return stuRet;
}
i=2;
j=0;
nUpto=(int)(sqrt(nInN*1.0));
while(i<=nUpto)
{
stuAl=stuGetOne(nInN,i);
if(stuAl.nPow>0)
{
stuRet.nFact[j]=stuAl.nFact;
stuRet.nPow[j]=stuAl.nPow;
j++;
nUpto=(int)(sqrt(nInN*1.0));
}
i++;
}
stuOneF stuGetOne(int & nInN,int nDiv);
if(nInN>1)
{
stuRet.nFact[j]=nInN;
stuRet.nPow[j]=1;
j++;
}
stuRet.nCount=j;
return stuRet;
}
void vOutput(stuAllFs stuAns)
{
int i;
int nAns=1;
for(i=1;i<=stuAns.nCount;i++)
{
nAns*=2*stuAns.nPow[i-1]+1;
}
cout << nAns << endl;
}
stuOneF stuGetOne(int & nInN,int nDiv)
{
stuOneF stuRet;
stuRet.nFact=nDiv;
stuRet.nPow=0;
while(nInN%nDiv==0)
{
nInN/=nDiv;
stuRet.nPow++;
}
return stuRet;
}
#include<stdio.h>
#include<math.h>
struct stuOne
{
int nNum;
int nPow;
};
struct stuAll
{
int nNum[50];
int nPow[50];
int nCount;
};
void vOutPut(struct stuAll stu)
{
int i;
int nPlus=1;
for(i=1;i<=stu.nCount;i++)
{
nPlus*=2*stu.nPow[i-1]+1;
}
printf("%d\n",nPlus);
}
stuOne stuGetOne(int &num,int i)
{
struct stuOne stuRet;
stuRet.nNum=i;
stuRet.nPow=0;
while(num%i==0)
{
num/=i;
stuRet.nPow++;
}
return stuRet;
}
stuAll getAll(int num)
{
struct stuAll stuRet;
struct stuOne stu0;
int i,j;
int endLine;
if(num<1)
{
stuRet.nCount=0;
return stuRet;
}
i=2;
j=0;
endLine=(int)sqrt(num*1.0);
while(i<=endLine)
{
stu0=stuGetOne(num,i);
if(stu0.nPow>0)
{
stuRet.nNum[j]=stu0.nNum;
stuRet.nPow[j]=stu0.nPow;
j++;
endLine=(int)sqrt(num*1.0);
}
i++;
}
stuOne stuGetOne(int &num,int i);
if(num>1)
{
stuRet.nNum[j]=num;
stuRet.nPow[j]=1;
j++;
}
stuRet.nCount=j;
return stuRet;
}
int main()
{
int n,i;
int num;
struct stuAll stu;
while(scanf("%d",&n)!=EOF)
{
for(i=1;i<=n;i++)
{
scanf("%d",&num);
stu=getAll(num);
vOutPut(stu);
}
}
return 0;
}
下面的程序是自己写的,今天终于搞定了,想想其实挺简单的,有了思路然后再一步步去实现,其中纠结了很久的一段代码原来是判断最后一个数字的,今天终于想通了。 :D
感谢自己的坚持!
#include<math.h>
using namespace std;
struct stuOneF
{
int nFact;
int nPow;
};
struct stuAllFs
{
int nFact[50];
int nPow[50];
int nCount;
};
stuAllFs stuGetAll(int nInN);
void vOutput(stuAllFs stuAns);
stuOneF stuGetOne(int & nInN,int nDiv);
int main()
{
int nCase;
int i;
stuAllFs stuAns;
int nInNum;
cin >> nCase;
for(i=1;i<=nCase;i++)
{
cin >> nInNum;
stuAns=stuGetAll(nInNum);
vOutput(stuAns);
}
return 0;
}
stuAllFs stuGetAll(int nInN)
{
stuAllFs stuRet;
stuOneF stuAl;
int i,j;
int nUpto;
if(nInN<1)
{
stuRet.nCount=0;
return stuRet;
}
i=2;
j=0;
nUpto=(int)(sqrt(nInN*1.0));
while(i<=nUpto)
{
stuAl=stuGetOne(nInN,i);
if(stuAl.nPow>0)
{
stuRet.nFact[j]=stuAl.nFact;
stuRet.nPow[j]=stuAl.nPow;
j++;
nUpto=(int)(sqrt(nInN*1.0));
}
i++;
}
stuOneF stuGetOne(int & nInN,int nDiv);
if(nInN>1)
{
stuRet.nFact[j]=nInN;
stuRet.nPow[j]=1;
j++;
}
stuRet.nCount=j;
return stuRet;
}
void vOutput(stuAllFs stuAns)
{
int i;
int nAns=1;
for(i=1;i<=stuAns.nCount;i++)
{
nAns*=2*stuAns.nPow[i-1]+1;
}
cout << nAns << endl;
}
stuOneF stuGetOne(int & nInN,int nDiv)
{
stuOneF stuRet;
stuRet.nFact=nDiv;
stuRet.nPow=0;
while(nInN%nDiv==0)
{
nInN/=nDiv;
stuRet.nPow++;
}
return stuRet;
}
#include<stdio.h>
#include<math.h>
struct stuOne
{
int nNum;
int nPow;
};
struct stuAll
{
int nNum[50];
int nPow[50];
int nCount;
};
void vOutPut(struct stuAll stu)
{
int i;
int nPlus=1;
for(i=1;i<=stu.nCount;i++)
{
nPlus*=2*stu.nPow[i-1]+1;
}
printf("%d\n",nPlus);
}
stuOne stuGetOne(int &num,int i)
{
struct stuOne stuRet;
stuRet.nNum=i;
stuRet.nPow=0;
while(num%i==0)
{
num/=i;
stuRet.nPow++;
}
return stuRet;
}
stuAll getAll(int num)
{
struct stuAll stuRet;
struct stuOne stu0;
int i,j;
int endLine;
if(num<1)
{
stuRet.nCount=0;
return stuRet;
}
i=2;
j=0;
endLine=(int)sqrt(num*1.0);
while(i<=endLine)
{
stu0=stuGetOne(num,i);
if(stu0.nPow>0)
{
stuRet.nNum[j]=stu0.nNum;
stuRet.nPow[j]=stu0.nPow;
j++;
endLine=(int)sqrt(num*1.0);
}
i++;
}
stuOne stuGetOne(int &num,int i);
if(num>1)
{
stuRet.nNum[j]=num;
stuRet.nPow[j]=1;
j++;
}
stuRet.nCount=j;
return stuRet;
}
int main()
{
int n,i;
int num;
struct stuAll stu;
while(scanf("%d",&n)!=EOF)
{
for(i=1;i<=n;i++)
{
scanf("%d",&num);
stu=getAll(num);
vOutPut(stu);
}
}
return 0;
}
下面的程序是自己写的,今天终于搞定了,想想其实挺简单的,有了思路然后再一步步去实现,其中纠结了很久的一段代码原来是判断最后一个数字的,今天终于想通了。 :D
感谢自己的坚持!