水A - Two Bases水题,但是pow的精度不高,被hack掉了。用long long能存的下#include using namespace std;typedef long long ll;const int N = 1e5 + 10;const int INF = 0x3f3f3f3f;...
分类:
其他好文 时间:
2015-11-25 13:28:48
阅读次数:
218
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
doublemy_pow(constdoublenumber,intn)
{
assert(number);
if(n>0)
{
returnnumber*my_pow(number,n-1);
}
elseif(n<0)
{
return(1/number)*my_pow(number,n+1);
}
else
retu..
分类:
其他好文 时间:
2015-11-25 01:17:11
阅读次数:
175
对于一个素数a,2^a-1叫做梅森数。 如果2^a-1为素数则叫做梅森素数。我们知道,如果a为合数,则2^a-1一定不是素数。2^a-1为素数,则a必为素数。如果a为素数,则2^a-1可为素数,也可为合数。unsigned long long multi_pow(unsigned long long...
分类:
其他好文 时间:
2015-11-21 00:38:40
阅读次数:
245
#include<stdio.h>
#include<stdlib.h>
intmy_pow(intn,intk)
{
k=k-1;
intsum=n;
if(k)
{
sum=my_pow(n,k)*n;
}
returnsum;
}
intmain()
{
intn=0;
intk=0;
scanf("%d%d",&n,&k);
intret=my_pow(n,k);
printf("%d\n",ret);
system("pause");
return0;
}
分类:
编程语言 时间:
2015-11-20 08:09:31
阅读次数:
218
题意: 求浮点型x的n次幂结果。思路: logN直接求,注意n可能为负数!!!当n=-2147483648的时候,千万别直接n=-n,这样的结果是多少?其他求法大同小异。 1 class Solution { 2 public: 3 double myPow(double x, int ...
分类:
其他好文 时间:
2015-11-19 00:31:05
阅读次数:
113
js是一门应用极其广泛的语言,它直接决定着一个前端工程师水平以及工资的高低,今天,本人这个前端菜鸟就来总结写js怎样结合数学进行应用。一:结合勾股定理进行苹果菜单的开发首先来介绍几个常用的公式1:平方公式 Math.pow(a,b);代表的是a的b次方;2:开方公式 Math.sqrt(a,b).....
分类:
Web程序 时间:
2015-11-15 14:43:51
阅读次数:
214
Implement pow(x,n).Subscribeto see which companies asked this question解法1:最简单的即是n个x直接相乘,毫无疑问会超时Time Limit Exceededclass Solution {public: double my...
分类:
其他好文 时间:
2015-11-12 19:55:19
阅读次数:
310
#include#includeint main(){ float x, y; scanf("%f,%f", &x, &y); if(pow((x-2),2)+pow((y-2),2)<=1||pow((x+2),2)+pow((y-2),2)<=1||pow((x-2),2)+p...
分类:
其他好文 时间:
2015-11-11 22:15:12
阅读次数:
152
题目来源: https://leetcode.com/problems/powx-n/题意分析: 实现一个整型的幂运算。题目思路: 幂运算可以利用二分的方法来做。也就是x^n = x ^ (n /2) * x ^(n / 2) (n %2 == 0)或者x^n = x ^ (n /2) * x...
分类:
编程语言 时间:
2015-11-10 19:30:59
阅读次数:
263
经验:看题目中的提示,严格按照提示中的数据来编写程序。#include#include#definePI3.1415927intmain(){doubler,s;while((scanf("%lf",&r))!=EOF){s=4.0/3*PI*pow(r,3);printf("%.3lf\n",s)...
分类:
其他好文 时间:
2015-11-06 14:24:28
阅读次数:
141