hdu 5429 Geometric Progression(java 大数)
来源:互联网 发布:算法分析 概述 ppt 编辑:程序博客网 时间:2024/05/16 08:23
Geometric Progression
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 286 Accepted Submission(s): 76
Problem Description
Determine whether a sequence is a Geometric progression or not.
In mathematics, a **geometric progression**, also known as a **geometric sequence**, is a sequence of numbers where each term after the first is found by multiplying the previous one by a fixed, non-zero number called the common ratio. For example, the sequence 2, 6, 18, 54, ... is a geometric progression with common ratio 3. Similarly 10, 5, 2.5, 1.25, ... is a geometric sequence with common ratio 1/2.
Examples of a geometric sequence are powersrk of a fixed number r, such as 2k and 3k . The general form of a geometric sequence is
a, ar, ar2, ar3, ar4, …
where r ≠ 0 is the common ratio and a is a scale factor, equal to the sequence's start value.
In mathematics, a **geometric progression**, also known as a **geometric sequence**, is a sequence of numbers where each term after the first is found by multiplying the previous one by a fixed, non-zero number called the common ratio. For example, the sequence 2, 6, 18, 54, ... is a geometric progression with common ratio 3. Similarly 10, 5, 2.5, 1.25, ... is a geometric sequence with common ratio 1/2.
Examples of a geometric sequence are powers
where r ≠ 0 is the common ratio and a is a scale factor, equal to the sequence's start value.
Input
First line contains a single integer T(T≤20) which denotes the number of test cases.
For each test case, there is an positive integern(1≤n≤100) which denotes the length of sequence,and next line has n nonnegative numbers Ai which allow leading zero.The digit's length of Ai no larger than 100 .
For each test case, there is an positive integer
Output
For each case, output "Yes" or "No".
Sample Input
41031 1 131 4 2516 8 4 2 1
Sample Output
YesYesNoYes
判断一个数列是否为等比数列。在数学中,等比数列,是一个数列,这个数列中的第一项之后的每一项是前一项乘上一个固定的非零实数(我们称之为公比)。比如,数列 2, 6, 18, 54, ... 是一个公比为3的等比数列。 类似的,10,5,2.5,1.25,...是一个公比为0.5的等比数列。等比数列的一般形式是:a,ar,ar2,ar3,ar4,...其中r!=0,r为公比,a是首项(a可以是任何实数)
题解:(1)存在0的时候要全都是0,才能是Yes,存在0但不全是0则是No
(2)不存在0,则A[i-1]*A[i+1]==A[i]*A[i]是否全都成立
import java.util.*;import java.math.*;public class Main {private static Scanner in;public static void main(String[] args) {in = new Scanner(System.in);BigInteger a, b, fz, fm, tt, fir;int t;t = in.nextInt();for (int i = 1; i <= t; i++) {int n;n = in.nextInt();int f = 1; // 等比int ff = 1; // 除第一位,其他都是0int f3 = 1; // 不存在0a = in.nextBigInteger();if (a.equals(BigInteger.ZERO) == false) {ff = 0;} elsef3 = 0;fir = a;if (n == 1) {System.out.println("Yes");continue;}b = in.nextBigInteger();if (b.equals(BigInteger.ZERO) == false) {ff = 0;} else {f3 = 0;}for (int j = 2; j < n; j++) {tt = in.nextBigInteger();if (tt.equals(BigInteger.ZERO) == false) {ff = 0;} else {f3 = 0;}if (f == 1) {if (a.multiply(tt).equals(b.multiply(b)) == false) {f = 0;}}a = b;b = tt;}if (ff == 1)System.out.println("Yes");// 全是0else if (f3 == 0)System.out.println("No"); // 有0else if (f == 0)System.out.println("No");elseSystem.out.println("Yes");}}}
0 0
- hdu 5429 Geometric Progression(java 大数)
- 【Java大数】hdu 5429 Geometric Progression
- HDU 5429-Geometric Progression(JAVA大数判断等比数列)
- HDU 5429 Geometric Progression
- hdu 5429 Geometric Progression (等比数列判定+大数模板)
- hdu 5429 Geometric Progression(高精度)
- hdu 5429 Geometric Progression(java 高精度+java输入外挂)
- HDU 5429 Geometric Progression(大数模板)——BestCoder Round #54(div.1 div.2)
- hdu 5429 Geometric Progression(高精度)
- BC - Geometric Progression (等比数列的性质 + java大数)
- BestCoder Round #54 (div.2)HDU 5429 Geometric Progression(1003)
- HDU 5433/BC 54C Geometric Progression
- Geometric Progression(等比数列的判断+java大数(同时附上别人很完美的C++大数模板))
- hash codeforces567C Geometric Progression
- BestCoder Round #54 (div.2) HDOJ 5429 Geometric Progression(模拟)
- 等比级数(geometric progression) 和等差数列
- CF-567C - Geometric Progression
- CodeForces #Pi C.Geometric Progression
- HDU1045 - Fire Net (深搜)
- 手工删除Oracle 12C数据库实例
- 【Python基础】Python面向对象 - 4 - 定制类的特殊方法
- 生成浮点型随机数相加
- Android UI之Notification
- hdu 5429 Geometric Progression(java 大数)
- hdu 4965 Fast Matrix Calculation(数学)
- 十年,这是一个新的开始
- 腾讯后台开发面试题--整理3
- spring mvc包含的功能
- Java第一周:1.3
- ubuntu 怎么以root权限登陆
- DICOM:DICOM三大开源库对比分析之“数据加载”
- Android谨防单例模式的内存泄露