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; }
Pascal :
var n,i,y:longint; procedure jian(var a:longint); begin while (a mod 2=0)or(a mod 3=0)or(a mod 5=0)do begin if a mod 2=0 then a:=a div 2; if a mod 3=0 then a:=a div 3; if a mod 5=0 then a:=a div 5 end end; function su(a:longint):boolean; var i:longint; begin su:=true; if a<>2 then for i:=2 to trunc(sqrt(a)) do if a mod i=0 then begin su:=true;break end; end; begin while not eof do begin readln(n); jian(n); y:=0; for i:=6 to n do if (n mod i=0)and(su(i)) then begin y:=1;writeln('0');break end; if y=0 then writeln('1') end end.
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
- 2193
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者