声明:题目部分皆为南阳OJ题目,代码部分包含AC代码(可能不止一个)和标程。

由于大数问题用c/c++写比较麻烦,而Java的大数类又很好用,所以基本为java代码。实际上竞赛很少会考大数问题,因为竞赛是比的算法,而不是语言特性,不过很多都是大数据,数据上千万级别的,所以算法又很关键,显然那和这篇博客也没啥关系。

题目不是太难,大家和本人就权当学习或复习下Java吧O(∩_∩)O~。

该分类南阳oj地址:http://acm.nyist.edu.cn/JudgeOnline/problemset.php?typeid=7 .
     本文由csdn-jtahstu原创,转载请注明出处,欢迎志同道合的朋友一起交流学习。本人QQ:1373758426和博客链接:blog.csdn.net/jtahstu

ok , 开始Y(^o^)Y

P28、

大数阶乘

时间限制:3000 ms  |  内存限制:65535 KB
难度:3
 
描述
我们都知道如何计算一个数的阶乘,可是,如果这个数很大呢,我们该如何去计算它并输出它?

 
输入
输入一个整数m(0<m<=5000)
输出
输出m的阶乘,并在输出结束之后输入一个换行符
样例输入
50
样例输出
30414093201713378043612608166064768844377641568960512000000000000
来源
经典题目
上传者

张云聪

 #include<stdio.h>
int a[1000001];
int main()
{
int n;
scanf("%d",&n);
int len=1;
a[1]=1;
for(int i=2; i<=n; ++i)
{
int b=0;
for(int j=1; j<=len; ++j)
{
int t=a[j]*i+b;
a[j]=t%10;
b=t/10;
if(j==len&&b!=0)
len++;
}
}
for(int i=len; i>0; --i)
printf("%d",a[i]);
printf("\n");
}
#include<stdio.h>//标程
#include<string.h>
const int maxn=20000;
int a[maxn];
int main() {
int n,i,j,s,c;
scanf("%d",&n);
memset(a,0,sizeof(a));
a[0]=1;
for(i=2; i<=n; i++) {
c=0;
for(j=0; j<=maxn; j++) {
s=a[j]*i+c;
a[j]=s%10;
c=s/10;
}
}
for(j=maxn; j>=0; j--) if(a[j]) break;
for(i=j; i>=0; i--) printf("%d",a[i]);
printf("\n");
return 0;
}

P45、

棋盘覆盖

直接给链接吧,这题的图复制过来有问题,http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=45
时间限制:3000 ms  |  内存限制:65535 KB
难度:3
描述

在一个2k×2k(1<=k<=100)的棋盘中恰有一方格被覆盖,如图1(k=2时),现用一缺角的2×2方格(图2为其中缺右下角的一个),去覆盖2k×2k未被覆盖过的方格,求需要类似图2方格总的个数s。如k=1时,s=1;k=2时,s=2

输入
第一行m表示有m组测试数据;
每一组测试数据的第一行有一个整数数k;
输出
输出所需个数s;
样例输入
3123
样例输出
1521
 /*
* http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=45
* by jtahstu on 2015/3/31 20:00
* (2^(2*k))/3 就是这个结果
*/
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static Scanner cin = new Scanner(System.in);
public static void main(String[] args) {
// TODO 自动生成的方法存根
int T = cin.nextInt();
while (T-- != 0) {
int k = cin.nextInt();
BigInteger ans=BigInteger.valueOf(2);
System.out.println(ans.pow(2*k).divide(BigInteger.valueOf(3))); }
}
}
 #include<iostream>//标程
#include<string.h>
using namespace std;
int main()
{
int n;
cin>>n;
while(n--)
{
int a[100];
memset(a,0,sizeof(a));
int size;
cin>>size;
a[0]=1;
if(size==1)
cout<<a[0]<<endl;
int i,j,k;
for(i=2;i<=size;++i)
{
for(j=0;j<100;++j)
a[j]=4*a[j];
a[0]++;
for(j=0;j<99;++j)
{
a[j+1]+=a[j]/10;
a[j]=a[j]%10;
}
}
for(i=99;i>=0;--i)
if(a[i]) break;
for(j=i;j>=0;--j)
cout<<a[j];
cout<<endl;
}
return 0;
}

P73、

比大小

时间限制:3000 ms  |  内存限制:65535 KB
难度:2
 
描述

给你两个很大的数,你能不能判断出他们两个数的大小呢?

比如123456789123456789要大于-123456

 
输入
每组测试数据占一行,输入两个不超过1000位的10进制整数a,b
数据保证输入的a,b没有前缀的0。
如果输入0 0表示输入结束。测试数据组数不超过10组
输出
如果a>b则输出“a>b”,如果a<b则输出“a<b”,如果相等则输出“a==b”。
样例输入
111111111111111111111111111 88888888888888888888
-1111111111111111111111111 22222222
0 0
样例输出
a>b
a<b
 #include <iostream>
#include <string>
using namespace std;
int main()
{
string s1, s2;
while (cin >> s1 >> s2,s1[0] != '0' && s2[0] != '0')
{
if (s1[0] == '-' && s2[0] != '-')
{
cout << "a<b" << endl;
}
else if (s2[0] == '-' && s1[0] != '-')
{
cout << "a>b" << endl;
}
else
{
if (s1[0] == '-' && s2[0] == '-') //为负数
{
if (s1.size() > s2.size())
cout << "a<b" << endl;
else if (s1.size() < s2.size())
cout << "a>b" << endl;
else if(s1 > s2) cout<<"a<b"<<endl;
else if(s1 < s2) cout<<"a>b"<<endl;
else cout << "a==b" << endl;
}
else //为正数
{
if (s1.size() > s2.size())
cout << "a>b" << endl;
else if (s1.size() < s2.size())
cout << "a<b" << endl;
else if(s1 > s2) cout<< "a>b" <<endl;
else if(s1 < s2) cout<< "a<b" <<endl;
else cout << "a==b" << endl;
}
}
}
}//Orz AC
 #include<iostream>//标程
#include<string>
using namespace std;
int main()
{
string a,b;
while(cin>>a>>b)
{
if(a=="0"&&b=="0")
return 0;
if(a==b)
cout<<"a==b"<<endl;
else if(a[0]=='-'&&b[0]=='-')
{
if(a.substr(1,string::npos)>b.substr(1,string::npos)||a.length()>b.length())
cout<<"a<b"<<endl;
else cout<<"a>b"<<endl;
}
else if(a>"0"&&b>"0"||a<"0"&&b<"0"&&a.length()>b.length()||a>b)
cout<<"a>b"<<endl;
else if(a<"0"&&b>"0"&&a.length()>b.length()||a>b)
cout<<"a<b"<<endl;
}
}

P103

A+B Problem II

时间限制:3000 ms  |  内存限制:65535 KB
难度:3
 
描述

I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.

A,B must be positive.

 
输入
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
输出
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the anequation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation.
样例输入
2
1 2
112233445566778899 998877665544332211
样例输出
Case 1:
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110
 /*
* http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=103
* by jtahstu on 2015/2/12 20:00
* hdu 1002
*/
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
int main() {
int n,count=0,m;
string a1,b1;
cin>>n;m=n;
while(n--) {
int a[1001]= {0},b[1001]= {0};
count++;
cin>>a1>>b1;
for(int i=0; i<a1.size(); i++)//大数相加算法
a[i]+=a1[a1.size()-i-1]-'0';
for(int i=0; i<b1.size(); i++)
b[i]+=b1[b1.size()-i-1]-'0';
for( int i = 0 ; i < 1001; i++ ) {
a[i] += b[i] ;
if( a[i] >= 10 ) {
a[i+1] += a[i]/10 ;
a[i]%=10;
}
}
int i;
for(i = 1000 ; i >= 0; i -- ) {
if( a[i] != 0 )break;
}
cout<<"Case "<<count<<":"<<endl;
cout<<a1<<" "<<"+"<<" "<<b1<<" "<<"="<<" ";
for(; i>=0; i--)
cout<<a[i];
cout<<endl;
// if(count!=m)//最后一行不能多一个换行,bt
// cout<<endl;
}
return 0;
}
 import java.math.BigInteger;//标程
import java.util.Scanner;
public class Main{
public static void main(String args[]) {
Scanner cin=new Scanner(System.in);
int n=cin.nextInt();
BigInteger a,b;
for(int i=1;i<=n;i++){
a=cin.nextBigInteger();
b=cin.nextBigInteger();
System.out.println("Case "+i+":");
System.out.println(a.toString()+" + "+b.toString()+" = "+a.add(b));
}
}
}

P114

某种序列

时间限制:3000 ms  |  内存限制:65535 KB
难度:4
 
描述
数列A满足An = An-1 + An-2 + An-3, n >= 3 
编写程序,给定A0, A1 和 A2, 计算A99

 
输入
输入包含多行数据 
每行数据包含3个整数A0, A1, A2 (0 <= A0, A1, A2 <= 100000000) 
数据以EOF结束
输出
对于输入的每一行输出A99的值
样例输入
1 1 1
样例输出
69087442470169316923566147
 /*
* http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=803
* by jtahstu on 2015/3/31 20:00
*/
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static Scanner cin = new Scanner(System.in);
public static void main(String[] args) {
// TODO 自动生成的方法存根
BigInteger res[] = new BigInteger[105];
while (cin.hasNext()) {
res[0] = cin.nextBigInteger();
res[1] = cin.nextBigInteger();
res[2] = cin.nextBigInteger();
for (int i = 3; i <= 99; i++) {
res[i] = res[i - 1].add(res[i - 2]).add(res[i - 3]);
}
System.out.println(res[99]);
}
}
}
 #include<stdio.h>//标程
#include<string.h>
#include <stdlib.h>
void add(char a[],char b[],char back[])
{
int i,j,k,up,x,y,z,l;
char *c;
if (strlen(a)>strlen(b)) l=strlen(a)+2; else l=strlen(b)+2;
c=(char *) malloc(l*sizeof(char));
i=strlen(a)-1;
j=strlen(b)-1;
k=0;up=0;
while(i>=0||j>=0)
{
if(i<0) x='0'; else x=a[i];
if(j<0) y='0'; else y=b[j];
z=x-'0'+y-'0';
if(up) z+=1;
if(z>9) {up=1;z%=10;} else up=0;
c[k++]=z+'0';
i--;j--;
}
if(up) c[k++]='1';
i=0;
c[k]='\0';
for(k-=1;k>=0;k--)
back[i++]=c[k];
back[i]='\0';
}
int main()
{
char a[3][1000],temp[1000];
int roll=3;
while(scanf("%s%s%s",a[0],a[1],a[2]) !=EOF)
{
for (int i=3;i<=99;i++)
{
add(a[(i-1)%3],a[(i-2)%3],temp);
add(temp,a[(i-3)%3],a[i%3]);
}
printf("%s\n",a[0]);
}
}

P155

求高精度幂

时间限制:3000 ms  |  内存限制:65535 KB
难度:2
描述

对数值很大、精度很高的数进行高精度计算是一类十分常见的问题。比如,对国债进行计算就是属于这类问题。

现在要你解决的问题是:对一个实数R( 0.0 < R < 99.999 ),要求写程序精确计算 R 的 n 次方(Rn),其中n 是整数并且 0 < =n <= 25。

输入
输入有多行,每行有两个数R和n,空格分开。R的数字位数不超过10位。
输出
对于每组输入,要求输出一行,该行包含精确的 R 的 n 次方。输出需要去掉前导的 0 后不要的 0 。如果输出是整数,不要输出小数点。
样例输入
95.123 120.4321 205.1234 156.7592  998.999 101.0100 12
样例输出
548815620517731830194541.899025343415715973535967221869852721.0000000514855464107695612199451127676715483848176020072635120383542976301346240143992025569.92857370126648804114665499331870370751166629547672049395302429448126.76412102161816443020690903717327667290429072743629540498.1075960194566517745610440100011.126825030131969720661201
 /*
* http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=155
* by jtahstu on 2015/3/31 20:00
*/
import java.math.BigDecimal;
import java.util.Scanner;
public class Main {
public static Scanner cin = new Scanner(System.in);
public static void main(String[] args) {
// TODO 自动生成的方法存根
BigDecimal rBigDecimal;
int n;
while (cin.hasNext()) {
rBigDecimal = cin.nextBigDecimal();
n = cin.nextInt();
/*
* BigDecimal ans=BigDecimal.ONE; for (int i = 0; i <n; i++) {
* ans=ans.multiply(rBigDecimal); }
* System.out.println(ans.stripTrailingZeros().toPlainString());
*/
String str = rBigDecimal.pow(n).stripTrailingZeros()
.toPlainString();
if (str.startsWith("0"))//需要删除小数点前面的0,我去
str = str.substring(1);
System.out.println(str);
}
} }
 import java.util.Scanner;//标程
import java.math.BigDecimal;
/**
*
* @author Administrator
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
BigDecimal d1=null;
int p;
String s1;
String s;
Scanner cin=new Scanner(System.in);
while(cin.hasNext()){
s1=cin.next();
p=cin.nextInt();
d1=new BigDecimal(s1);
s=d1.pow(p).stripTrailingZeros().toPlainString();
for(int i=0;i<s.length();i++){
if(i==0&&s.charAt(i)=='0')
continue;
System.out.print(s.charAt(i));
}
System.out.println();
}
}
}

P513

A+B Problem IV

时间限制:1000 ms  |  内存限制:65535 KB
难度:3
 
描述
acmj最近发现在使用计算器计算高精度的大数加法时很不方便,于是他想着能不能写个程序把这个问题给解决了。

 
输入
包含多组测试数据
每组数据包含两个正数A,B(可能为小数且位数不大于400)
输出
每组输出数据占一行,输出A+B的结果,结果需要是最简的形式。
样例输入
1.9 0.1
0.1 0.9
1.23 2.1
3 4.0
样例输出
2
1
3.33
7
<pre name="code" class="java"> /*
* http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=513
* by jtahstu on 2015/3/31 19:00
*/
import java.math.BigDecimal;
import java.util.Scanner;
public class Main {
public static Scanner cin = new Scanner(System.in);
public static void main(String[] args) {
// TODO 自动生成的方法存根
BigDecimal abigDecimal, bbigDecimal;
while (cin.hasNext()) {
abigDecimal = cin.nextBigDecimal();
bbigDecimal = cin.nextBigDecimal();
if (abigDecimal.add(bbigDecimal).compareTo(BigDecimal.ZERO) == 0)
System.out.println("0");
else
System.out.println(abigDecimal.add(bbigDecimal)
.stripTrailingZeros().toPlainString());
}
}
}

 #include <stdio.h>//标程
#include <string.h>
#define MAX 1000
char a[MAX],b[MAX],c[MAX];
int main()
{
int i,j,k,l,m,n,la,lb,mx;
char ch;
memset(a,'0',sizeof(a));
memset(b,'0',sizeof(b));
while(~scanf("%s%s",a,b))
{
la=strlen(a);
lb=strlen(b);
a[la]='0';
b[lb]='0';
i=0;
while((a[i]-'.')&&i<la)
{
i++;
}
if(i==la)
a[la]='.';
j=0;
while((b[j]-'.')&&j<lb)
{
j++;
}
if(j==lb)
b[lb]='.';
m=(la-i)>(lb-j)?(la-i):(lb-j);
if(i>=j)
{
for(l=mx=i+m,k=0,j=i-j;l>=0;l--)
{
if(a[l]=='.')
{
c[l]='.';
continue;
}
ch=(l-j)<0?'0':b[l-j];
c[l]=(a[l]-'0'+ch-'0'+k)%10+'0';
k=(a[l]-'0'+ch-'0'+k)/10;
}
}
else
{
for(l=mx=j+m,k=0,j=j-i;l>=0;l--)
{
if(b[l]=='.')
{
c[l]='.';
continue;
}
ch=(l-j)<0?'0':a[l-j];
c[l]=(ch-'0'+b[l]-'0'+k)%10+'0';
k=(ch-'0'+b[l]-'0'+k)/10;
}
}
if(k>0)
printf("%d",k);
while(c[mx]=='0')
mx--;
if(c[mx]=='.')
mx--;
for(i=0;i<=mx;i++)
printf("%c",c[i]);
printf("\n");
memset(a,'0',sizeof(a));
memset(b,'0',sizeof(b));
}
}

P517

最小公倍数

时间限制:1000 ms  |  内存限制:65535 KB
难度:3
 
描述
为什么1小时有60分钟,而不是100分钟呢?这是历史上的习惯导致。
但也并非纯粹的偶然:60是个优秀的数字,它的因子比较多。
事实上,它是1至6的每个数字的倍数。即1,2,3,4,5,6都是可以除尽60。
 
我们希望寻找到能除尽1至n的的每个数字的最小整数m.
 
输入
多组测试数据(少于500组)。
每行只有一个数n(1<=n<=100).
输出
输出相应的m。
样例输入
2
3
4
样例输出
2
6
12
 /*
* http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=517
* by jtahstu on 2015/3/31 20:00
*/
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
static BigInteger jt(BigInteger a,BigInteger b)
{
return (b.compareTo(BigInteger.valueOf(0))==0)?a:jt(b, a.mod(b));
}
static BigInteger tt(BigInteger a,BigInteger b)
{
return a.multiply(b).divide(jt(a, b));
}
public static Scanner cin = new Scanner(System.in);
public static void main(String[] args) {
// TODO 自动生成的方法存根
BigInteger res[]=new BigInteger[105];
int n;
res[1]=BigInteger.valueOf(1);
for(int i=2;i<=100;i++){
res[i]=tt(BigInteger.valueOf(i), res[i-1]);
}
while(cin.hasNext()){
n=cin.nextInt();
System.out.println(res[n]);
}
}
}
 #include <math.h>//标程
#include <stdio.h>
#include <string.h>
const int M = 120;
bool not_prime[M];
int prime[30], point[30];
struct Ac
{
int num[50];
int len;
}ans;
void ac_table()
{
int top = -1;
for(int i=2;i<M;i++)
if(not_prime[i] == false)
{
prime[++top]=i;
for(int j=2*i;j<M;j+=i)
not_prime[j] = true;
}
}
void Init()
{
memset(point,0,sizeof(point));
memset(ans.num,0,sizeof(ans.num));
ans.num[0] = 1;
ans.len = 0;
}
void my_pow(Ac &c,int x)
{
for(int i=0;i<=c.len;i++)
c.num[i] *= x;
for(int i=0;i<=c.len;i++)
if(c.num[i] >= 10000)
{
c.num[i+1] += c.num[i]/10000;
c.num[i] = c.num[i]%10000;
}
c.len = c.num[c.len+1]==0 ? c.len : c.len+1;
}
void Print(Ac &c)
{
for(int i=c.len;i>=0;i--)
printf(i==c.len? "%d" : "%04d",c.num[i]);
printf("\n");
}
void divide(int x)
{
for(int i=0;prime[i]<=x;i++)
{
int tmp = 0;
while(x%prime[i]==0)
{
tmp++;
x /= prime[i];
}
if(tmp > point[i])
{
my_pow(ans,pow(prime[i] ,tmp - point[i]));
point[i] = tmp;
}
}
}
int main()
{
int n;
ac_table();
while(~scanf("%d",&n))
{
Init();
for(int i=2;i<=n;i++)
divide(i);
Print(ans);
}
return 0;
}

P524

A-B Problem

时间限制:1000 ms  |  内存限制:65535 KB
难度:3
 
描述

A+B问题早已经被大家所熟知了,是不是很无聊呢?现在大家来做一下A-B吧。

现在有两个实数A和B,聪明的你,能不能判断出A-B的值是否等于0呢?

 
输入
有多组测试数据。每组数据包括两行,分别代表A和B。
它们的位数小于100,且每个数字前中可能包含+,- 号。
每个数字前面和后面都可能有多余的0。
每组测试数据后有一空行。
输出
对于每组数据,输出一行。
如果A-B=0,输出YES,否则输出NO。
样例输入
1
1 1.0
2.0
样例输出
YES
NO
 /*
* http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=524
* by jtahstu on 2015/3/31 20:00
*/
import java.math.BigDecimal;
import java.util.Scanner; public class Main {
public static Scanner cin = new Scanner(System.in);
public static void main(String[] args) {
// TODO 自动生成的方法存根
BigDecimal a,b;
while(cin.hasNext()){
a=cin.nextBigDecimal();
b=cin.nextBigDecimal();
//cin.nextLine();//这里留意下
if(a.compareTo(b)==0)
System.out.println("YES");
else {
System.out.println("NO");
}
}
} }
#include <stdio.h>//标程
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
const int M=100;
void back(char* c,int &l)
{
if(strchr(c,'.') == NULL)
return ;
for(int i=l-1;i>=1;i--)
{
if(c[i]!='0')
break;
l--;
}
if(c[l-1]=='.')
l--;
c[l]='\0';
//puts("after back->");
//puts(c);
}
void front(char* c,int &l,bool &f)
{
int cnt = isdigit(c[0]) ? 0 : 1;
if(c[0]=='-')
f = false;
for(int i=cnt;i<l-1;i++)
{
if(c[i+1]=='.' || c[i]!='0')
break;
cnt++;
}
if(cnt)
{
for(int i=0;i<l-cnt;i++)
c[i] = c[i+cnt];
c[l-cnt] = '\0';
}
//puts("after front->");
//printf(f?"+ ":"- ");
//puts(c);
}
void deal(char *c,bool &f)
{
int l = strlen(c);
f = true;
back(c,l);
front(c,l,f);
}
bool Cmp(char* A,char* B,bool a,bool b)
{
if(strcmp(A,B) == 0)
{
if(strcmp(A,"0") == 0 || a^b == 0)
return true;
}
return false;
}
int main()
{
char A[M],B[M];
bool a,b;
while(~scanf("%s%s",A,B))
{
deal(A,a);
deal(B,b);
puts(Cmp(A,B,a,b)?"YES":"NO");
} return 0;
}

P655

光棍的yy

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
 
描述

yy经常遇见一个奇怪的事情,每当他看时间的时候总会看见11:11,这个很纠结啊

现在给你m个1,你可以把2个1组合成一个2,这样就不是光棍了,问这样的组合有多少种??

例如(111  可以拆分为 111 12 21  有三种)

 
输入
第一行输入一个n表示有n个测试数据
以下n行,每行输入m个1
(1 <= n,m <= 200)
输出
输出这种组合种数,占一行
样例输入
3
11
111
11111
样例输出
2
3
8
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static Scanner cin = new Scanner(System.in);
public static void main(String[] args) {
// TODO 自动生成的方法存根
int n = cin.nextInt();
BigInteger a[] = new BigInteger[201];
a[1] = BigInteger.valueOf(1);
a[2] = BigInteger.valueOf(2);
for (int i = 3; i <= 200; i++)
a[i] = a[i - 1].add(a[i - 2]);//递推,只是这是大数
while (n-- > 0) {
String s;
s = cin.next();
int len = s.length();
System.out.println(a[len]);
}
}
}

P773

开方数

时间限制:500 ms  |  内存限制:65535 KB
难度:3
 
描述
现在给你两个数 n 和 p ,让你求出 p 的开 n 次方。

 
输入
每组数据包含两个数n和p。当n和p都为0时表示输入结束。(1<=n<=200,1<=p<=10^101)
输出
对于每个输出对用输出开方后的结果k(结果小于10^9)。
样例输入
2 16
3 27
7 4357186184021382204544
0 0
样例输出
4
3
1234
import java.util.Scanner;

public class Main {
public static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
while (true) {
int n = input.nextInt();
double p = input.nextDouble();
if (n == 0 && p == 0)
break;
System.out.println(String.format("%.0f", Math.pow(p, 1.0 / n)));
}
}
}
 #include <stdio.h>//标程
#include <string.h>
#include <math.h>
int main()
{
//freopen("Input.txt","r",stdin);
//freopen("Output1.txt","w",stdout);
long mid,left,right;
double p;
int n;
while(~scanf("%d%lf",&n,&p)){
if(n==0 && p==0.0) break;
left=0,right=1000000000;
while(left<right)
{
mid=(left+right)/2;
if(pow(mid,n)==p) break;
if(pow(mid,n)<p)left=mid;
if(pow(mid,n)>p)
right=mid;
}
//printf("%lf\n",p);
printf("%ld\n",mid);
}
return 0;
}

P803

A/B Problem

时间限制:1000 ms  |  内存限制:65535 KB
难度:3
 
描述

做了A+B Problem,A/B Problem不是什么问题了吧!

 
输入
每组测试样例一行,首先一个号码A,中间一个或多个空格,然后一个符号( / 或者 % ),然后又是空格,后面又是一个号码B,A可能会很长,B是一个int范围的数。
输出
输出结果。
样例输入
110 / 100
99 % 10
2147483647 / 2147483647
2147483646 % 2147483647
样例输出
1
9
1
2147483646
 /*
* http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=803
* by jtahstu on 2015/3/31 20:00
*/ import java.math.BigInteger;
import java.util.Scanner; public class Main {
public static Scanner cin = new Scanner(System.in);
public static void main(String[] args) {
// TODO 自动生成的方法存根
String string;
BigInteger a,b;
while(cin.hasNext()){
a=cin.nextBigInteger();
string=cin.next();
b=cin.nextBigInteger();
if(string.compareTo("/")==0)
System.out.println(a.divide(b));
else
System.out.println(a.mod(b)); }
}
}

大数分类里就这12道题,Java复习的怎么样了啊?接下来应该会写分类的STL练习,容我先把题A完再来写,这几天应该就可以了。(*^-^*)

akoj-1048-求某一整数序列的全排列问题的更多相关文章

  1. //给定N个整数序列{A1,A2,A3...An},求函数f(i,j)=(k=i~j)Ak的求和

    //给定N个整数序列{A1,A2,A3...An},求函数f(i,j)=(k=i~j)Ak的求和 # include<stdio.h> void main() { ,sum1; ]={,- ...

  2. 11. 求奇数分之一序列前N项和

    求奇数分之一序列前N项和 #include <stdio.h> int main() { int denominator, i, n; double item, sum; while (s ...

  3. 10. 求N分之一序列前N项和

    求N分之一序列前N项和 #include <stdio.h> int main() { int i, n; double item, sum; while (scanf("%d& ...

  4. IT公司100题-9-判断整数序列是不是二元查找树的后序遍历结果

    问题描述: 输入一个整数数组,判断该数组是不是某二元查找树的后序遍历的结果. 如果是返回true,否则返回false. 例如输入4, 8, 6, 12, 16, 14, 10,由于这一整数序列是如下树 ...

  5. Interview----判断整数序列是否是二叉搜索树的后序遍历结果

    题目:输入一个整数数组,判断该数组是不是某二元查找树的后序遍历的结果. 如果是返回true,否则返回false. 例如输入5.7.6.9.11.10.8,由于这一整数序列是如下树的后序遍历结果:   ...

  6. c 求两个整数的最大公约数和最小公倍数

    //求最大公约数是用辗转相除法,最小公倍数是根据公式 m,n 的 最大公约数* m,n最小公倍数 = m*n 来计算 #include<stdio.h> //将两个整数升序排列 void ...

  7. 求两个整数的最大公约数GCM

    思路分析: (1)求差判定法:  如果两个数相差不大,可以用大数减去小数,所得的差与小数的最大公约数就是原来两个数的最大公约数.例如:求78和60的最大公约数.78-60=18,18和60的最大公约数 ...

  8. 给定一个正整数,实现一个方法求出离该整数最近的大于自身的 换位数 <把一个整数各个数位进行全排列>

    """给定一个正整数,实现一个方法求出离该整数最近的大于自身的 换位数 -> 把一个整数各个数位进行全排列""" # 使用 permu ...

  9. 《剑指offer》写一个函数,求两个整数之和,要求在函数体内不得使用+、-、*、/四则运算符号。

    弱菜刷题还是刷中文题好了,没必要和英文过不去,现在的重点是基本代码能力的恢复. [题目] 剑指offer 写一个函数,求两个整数之和,要求在函数体内不得使用+.-.*./四则运算符号. [思路] 直觉 ...

随机推荐

  1. vuex构建笔记本应用学习

    vuex:针对vue应用派生的专门管理应用state的工具,state可以理解为我们组件需要操作的data数据,都知道,vue构建spa应用的时候,随着组件规模的提升,各个子组件之间的通信如果采用子组 ...

  2. c#进程间通信(Inter-Process Communication)

    原文:c#进程间通信(Inter-Process Communication) c#进程间通信(IPC, Inter-Process Communication) 接收端: using System; ...

  3. 2015必须要看的APP源码

    多媒体类型 哔哩哔哩(bilibili)客户端源码 一个高仿哔哩哔哩(bilibili)客户端的开源项目,效果不错 下载地址: http://www.apkbus.com/forum.php?mod= ...

  4. 【转】Android中定时器的3种实现方法

    原文网址:http://www.android-study.com/pingtaikaifa/508.html 在Android开发中,定时器一般有以下3种实现方法: 一.采用Handler与线程的s ...

  5. js设计模式系列之(一)请节约你的请求-代理模式

    What’s the proxy pattern? 代理模式其实就是将违反单一性原则的类给抽离出来,尽量满足开放和封闭的原则. 相当于一个类的行为只是一种,但是你可以给这个类添加额外的行为.比如: 一 ...

  6. URAL 1658

    题目大意:求出T个最小的满足各个位的和为S1,平方和为S2的数.按顺序输出.数的位数大于100或者不存在这样一个数时,输出:No solution. KB     64bit IO Format:%I ...

  7. java 读取mysql库表数据

    import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import ...

  8. 看了一本书,说可以利用Hierarchy Viewer优化布局

    看了一本书,说可以利用Hierarchy Viewer优化布局,今以志之. 参考:http://www.cnblogs.com/Rocky_/archive/2011/11/04/2236243.ht ...

  9. C#Equal的使用

    代码如下: public partial class FramMain : Form { public FramMain() { InitializeComponent(); } private vo ...

  10. C#用注册表开机自动启动某某软件

    代码如下: public static void chkAutoRun(bool isRun) { if (isRun)//开机自动启动 { try { RegistryKey runKey = Re ...