GT and sequence
Accepts: 385
Submissions: 1467
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
Problem Description
You are given a sequence of NN integers.
You should choose some numbers(at least one),and make the product of them as big as possible.
It guaranteed that the absolute value of any product of the numbers you choose in the initial sequence will not bigger than 2^{63}-12?63??−1.
Input
In the first line there is a number TT (test numbers).
For each test,in the first line there is a number NN,and in the next line there are NN numbers.
1 \leq T \leq 10001≤T≤1000 1 \leq N \leq 621≤N≤62
You‘d better print the enter in the last line when you hack others.
You‘d better not print space in the last of each line when you hack others.
Output
For each test case,output the answer.
Sample Input
1 3 1 2 3
Sample Output
6wa代码:
1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 #include<math.h> 5 using namespace std; 6 const int MAXN=1010; 7 int cmd(int a,int b){ 8 return a>b; 9 } 10 int main(){ 11 int T,N; 12 int m[MAXN]; 13 scanf("%d",&T); 14 while(T--){ 15 scanf("%d",&N); 16 for(int i=0;i<N;i++){ 17 scanf("%d",m+i); 18 } 19 sort(m,m+N,cmd); 20 long long ans=fabs(m[0]); 21 for(int i=1;i<N;i++){ 22 if(fabs(ans*m[i])>ans)ans=fabs(ans*m[i]); 23 } 24 printf("%lld\n",ans); 25 } 26 return 0; 27 }
GT and numbers
Accepts: 146
Submissions: 939
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
Problem Description
You are given two numbers NN and MM.
Every step you can get a new NN in the way that multiply NN by a factor of NN.
Work out how many steps can NN be equal to MM at least.
If N can‘t be to M forever,print -1−1.
Input
In the first line there is a number TT.TT is the test number.
In the next TT lines there are two numbers NN and MM.
T\leq1000T≤1000, 1\leq N \leq 10000001≤N≤1000000,1 \leq M \leq 2^{63}1≤M≤2?63??.
Be careful to the range of M.
You‘d better print the enter in the last line when you hack others.
You‘d better not print space in the last of each line when you hack others.
Output
For each test case,output an answer.
Sample Input
3 1 1 1 2 2 4
Sample Output
0 -1 1wa代码:
1 HACK 2 #include<stdio.h> 3 #include<math.h> 4 #include<string.h> 5 #include<algorithm> 6 using namespace std; 7 int cmd(int a,int b){ 8 return a>b; 9 } 10 int main(){ 11 __int64 T,N,M; 12 scanf("%I64d",&T); 13 __int64 fac[10010]; 14 while(T--){ 15 scanf("%I64d%I64d",&N,&M); 16 if(M%N!=0){ 17 puts("-1"); 18 continue; 19 } 20 __int64 t=0; 21 __int64 n=N; 22 for(__int64 i=2;i<=n;i++){ 23 if(n%i==0){ 24 fac[t++]=i; 25 } 26 } 27 n=M/N; 28 __int64 ans=0; 29 sort(fac,fac+t,cmd); 30 for(__int64 i=0;i<t;i++){ 31 while(n%(fac[i])==0)n/=fac[i],ans++; 32 } 33 // for(int i=0;i<t;i++)printf("%d ",fac[i]);puts(""); 34 if(n==1)printf("%I64d\n",ans); 35 else puts("-1"); 36 } 37 return 0; 38 }