1 条题解
-
0
C :
#include<stdio.h> int main() { int n; while(scanf("%d",&n)!=EOF) { while(n%2==0) n/=2; while(n%3==0) n/=3; while(n%5==0) n/=5; if(n==1) printf("1\n"); else printf("0\n"); } return 0; }C++ :
#include <stdio.h> bool IsUgly(int number) { while(number % 2 == 0) number /= 2; while(number % 3 == 0) number /= 3; while(number % 5 == 0) number /= 5; return (number == 1) ? true : false; } int main() { int n; while(scanf("%d",&n)!=EOF) { printf("%d\n",IsUgly(n)); } return 0; }Java :
import java.math.BigInteger; import java.util.Scanner; public class Main { private static final BigInteger FIVE = new BigInteger("5"); private static final BigInteger THREE = new BigInteger("3"); private static final BigInteger TWO = new BigInteger("2"); private static final BigInteger ONE = new BigInteger("1"); private static final BigInteger ZERO = new BigInteger("0"); public static void main(String[] args) { // TODO Auto-generated method stub Scanner cin = new Scanner(System.in); BigInteger bigInteger; while(cin.hasNext()) { bigInteger = cin.nextBigInteger(); if(isPass(bigInteger)) System.out.println("1"); else System.out.println("0"); } } public static boolean isPass(BigInteger bigInteger) { while( bigInteger.equals(ONE)==false && bigInteger.mod(FIVE).equals(ZERO) ) { bigInteger=bigInteger.divide(FIVE); } while( bigInteger.equals(ONE)==false && bigInteger.mod(THREE).equals(ZERO) ) { bigInteger=bigInteger.divide(THREE); } while( bigInteger.equals(ONE)==false && bigInteger.mod(TWO).equals(ZERO) ) { bigInteger=bigInteger.divide(TWO); } if( bigInteger.equals(ONE)) return true; return false; } }
- 1
信息
- ID
- 1919
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者