File tree Expand file tree Collapse file tree 1 file changed +77
-0
lines changed
Expand file tree Collapse file tree 1 file changed +77
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+
3+ import java.util.* ;
4+
5+ import java.io.* ;
6+
7+ public class Solution {
8+
9+ // IO field
10+ static BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
11+ static BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System . out));
12+ static StringTokenizer st = new StringTokenizer (" " );
13+
14+ static void nextLine () throws Exception {st = new StringTokenizer (br .readLine ());}
15+ static String nextToken() throws Exception {
16+ while (! st. hasMoreTokens()) nextLine();
17+ return st. nextToken();
18+ }
19+ static int nextInt() throws Exception { return Integer . parseInt(nextToken()); }
20+ static long nextLong() throws Exception { return Long . parseLong(nextToken()); }
21+ static double nextDouble() throws Exception { return Double . parseDouble(nextToken()); }
22+ static void bwEnd() throws Exception {bw. flush();bw. close();}
23+
24+
25+ // Additional field
26+
27+ static long N , K ;
28+
29+ //
30+
31+ public static void main(String [] args) throws Exception {
32+
33+ int TC = nextInt();
34+ for (int tc= 1 ;tc<= TC ;tc++ ) {
35+
36+ ready();
37+ solve(tc);
38+
39+ }
40+ bwEnd();
41+
42+ }
43+
44+ static void ready() throws Exception {
45+
46+ N = nextInt();
47+ K = nextInt();
48+
49+ }
50+
51+ static void solve(int tc) throws Exception {
52+ bw. write(" #" + tc + " " );
53+
54+ long ans = 1 ;
55+ for (long i= 2 ;i* i<= K ;i++ ) {
56+ long cnt = 0 , d = 1 ;
57+ while (K % i == 0 ) {
58+ d *= i;
59+ K /= i;
60+ cnt++ ;
61+ }
62+ long ncnt = 0 ;
63+ for (long j= i;j<= N ;j*= i) ncnt += N / j;
64+ while (cnt- ncnt> 0 ) {
65+ cnt-- ;
66+ d /= i;
67+ }
68+ ans *= d;
69+ }
70+ if (N / K >= 1 ) ans *= K ;
71+ bw. write(ans + " \n " );
72+
73+ }
74+
75+ }
76+
77+ ```
You can’t perform that action at this time.
0 commit comments