为什么在北大poj 1845上不能AC?结果明明正确,它却提示编译错误。。。。求大神帮帮忙看看!!
北大poj1845DescriptionConsidertwonaturalnumbersAandB.LetSbethesumofallnaturaldivisorsof...
北大poj 1845
Description
Consider two natural numbers A and B. Let S be the sum of all natural divisors of A^B. Determine S modulo 9901 (the rest of the division of S by 9901).
Input
The only line contains the two natural numbers A and B, (0 <= A,B <= 50000000)separated by blanks.
Output
The only line of the output will contain S modulo 9901.
Sample Input
2 3
Sample Output
15
Hint
2^3 = 8.
The natural divisors of 8 are: 1,2,4,8. Their sum is 15.
15 modulo 9901 is 15 (that should be output).
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int x,y;
while(cin>>x>>y)
{
int n=pow(x,y);
int sum=0;
for(int i=1;i<=n;++i)
{
if(n%i==0)
sum+=i;
}
cout<<sum<<endl;
}
return 0;
} 展开
Description
Consider two natural numbers A and B. Let S be the sum of all natural divisors of A^B. Determine S modulo 9901 (the rest of the division of S by 9901).
Input
The only line contains the two natural numbers A and B, (0 <= A,B <= 50000000)separated by blanks.
Output
The only line of the output will contain S modulo 9901.
Sample Input
2 3
Sample Output
15
Hint
2^3 = 8.
The natural divisors of 8 are: 1,2,4,8. Their sum is 15.
15 modulo 9901 is 15 (that should be output).
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int x,y;
while(cin>>x>>y)
{
int n=pow(x,y);
int sum=0;
for(int i=1;i<=n;++i)
{
if(n%i==0)
sum+=i;
}
cout<<sum<<endl;
}
return 0;
} 展开
2个回答
展开全部
因为0 <= A,B <= 50000000,当直接计算A^B的值的时候超出了int的表示范围,应该改变这种暴搜的算法
你看下这个回答,能给你算法思路一个启发
http://zhidao.baidu.com/question/525446462.html
你看下这个回答,能给你算法思路一个启发
http://zhidao.baidu.com/question/525446462.html
帕剌斯
2024-10-30 广告
2024-10-30 广告
德国Palas 成立于1983年,总部位于德国巴登符腾堡州的卡尔斯鲁厄。作为气溶胶技术专家, Palas 致力于为用户提供气溶胶颗粒物的产生、处理、测量与分析解决方案,是该领域内全球先进的开发商和制造商。基于自身技术的独特优势,Palas ...
点击进入详情页
本回答由帕剌斯提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询