Created
October 7, 2013 07:03
-
-
Save phonism/6863600 to your computer and use it in GitHub Desktop.
LightOJ 1028 - Trailing Zeroes (I) http://lightoj.com/volume_showproblem.php?problem=1028
统计约数的个数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOError; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.io.OutputStreamWriter; | |
import java.io.PrintWriter; | |
import java.util.StringTokenizer; | |
public class P1028 { | |
static final int maxn = 1000100; | |
int[] prime = new int[maxn]; | |
boolean[] check = new boolean[maxn]; | |
int cnt = 0; | |
void getPrime() { | |
for (int i = 2; i < maxn; i++) { | |
if (check[i] == false) | |
prime[cnt++] = i; | |
for (int j = 0; j < cnt; j++) { | |
if ((long) i * prime[j] >= maxn) | |
break; | |
check[i * prime[j]] = true; | |
} | |
} | |
} | |
public void run() { | |
Scanner cin = new Scanner(System.in); | |
PrintWriter cout = new PrintWriter(new OutputStreamWriter(System.out)); | |
getPrime(); | |
int test = cin.nextInt(); | |
for (int cas = 1; cas <= test; cas++) { | |
long n = cin.nextLong(); | |
int res = 1; | |
for (int i = 0; (long) prime[i] * prime[i] <= n; i++) { | |
int cnt = 1; | |
while (n % prime[i] == 0) { | |
n /= prime[i]; | |
cnt++; | |
} | |
res *= (long) cnt; | |
} | |
if (n > 1) | |
res *= 2; | |
System.out.println("Case " + cas + ": " + (res - 1)); | |
} | |
cout.flush(); | |
} | |
public static void main(String args[]) { | |
new P1028().run(); | |
} | |
class Scanner { | |
BufferedReader br; | |
StringTokenizer st; | |
Scanner(InputStream in) { | |
br = new BufferedReader(new InputStreamReader(in)); | |
eat(""); | |
} | |
void eat(String s) { | |
st = new StringTokenizer(s); | |
} | |
String nextLine() { | |
try { | |
return br.readLine(); | |
} catch (IOException e) { | |
throw new IOError(e); | |
} | |
} | |
boolean hasNext() { | |
while (!st.hasMoreTokens()) { | |
String s = nextLine(); | |
if (s == null) | |
return false; | |
eat(s); | |
} | |
return true; | |
} | |
String next() { | |
hasNext(); | |
return st.nextToken(); | |
} | |
int nextInt() { | |
return Integer.parseInt(next()); | |
} | |
long nextLong() { | |
return Long.parseLong(next()); | |
} | |
double nextDouble() { | |
return Double.parseDouble(next()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment