题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6298
题型:思维+暴力
1=12+13+16=13+13+13=12+14+14
1
=
1
2
+
1
3
+
1
6
=
1
3
+
1
3
+
1
3
=
1
2
+
1
4
+
1
4
.
其实找找规律就知道只有3的倍数或4的倍数才能分解
比赛的时候java卡了,就写了个C的,结束了再补了java的
C版本
#include<stdio.h>
#include<math.h>
#include<string.h>
int t;
unsigned long long int a;
int main()
{
scanf("%d",&t);
while(t--){
scanf("%lld",&a);
if(a%3==0){
printf("%lld\n",(a/3)*(a/3)*(a/3));
continue;
}else if(a%4==0){
printf("%lld\n",(a/4)*(a/4)*(a/2));
continue;
}
printf("-1\n");
}
return 0;
}
java版本
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
public class Main {
static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
public static int nextInt() throws IOException {
in.nextToken();
return (int) in.nval;
}
public static long nextLong() throws IOException {
in.nextToken();
return (long) in.nval;
}
public static String next() throws IOException {
in.nextToken();
return (String) in.sval;
}
public static void main(String[] args) throws IOException {
int n = nextInt();
long a;
while (n-- > 0) {
a= nextLong();
if (a % 3 == 0) {
out.println((a / 3) * (a / 3) * (a / 3));
continue;
} else if (a % 4 == 0) {
out.println((a / 2) * (a / 4) * (a / 4));
continue;
}
out.println(-1);
}
out.flush();
}
}