package com.supermars.practice; import java.util.Scanner; public class 除法表达式 { static Scanner cin = new Scanner(System.in); public static void main(String[] args) { while (cin.hasNext()) { String s = cin.next(); String X[] = s.split("/"); int fenmu = 0; loop: for (int i = 0; i < X.length; i++) { fenmu = Integer.parseInt(X[i]); for (int j = 0; j < i; j++) { int g = gcd(Integer.parseInt(X[j]), fenmu); fenmu /= g; if (fenmu == 1) break loop; } for (int j = i + 1; j < X.length; j++) { int g = gcd(Integer.parseInt(X[j]), fenmu); fenmu /= g; if (fenmu == 1) break loop; } } System.out.println((fenmu == 1) ? "YES" : "NO"); } } private static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } }
package com.supermars.practice; import java.util.Arrays; import java.util.Scanner; public class 无平方因子数 { static Scanner cin = new Scanner(System.in); static int vis[] = new int[1<<10]; static int prim[]; public static void main(String[] args) { while (cin.hasNext()) { int n = cin.nextInt(); int m = cin.nextInt(); //int t = (int) Math.sqrt(m + 0.5); prim = new int[m]; int cnt = 0; for (int i = 2; i <= m; i++) { if (vis[i] == 0) prim[cnt++] = i; for (int j = i * i; j <= m; j += i) { vis[j] = 1; } } System.out.println(cnt); /* int count=cnt; for (int i = 0; i < cnt; i++) { int p = prim[i]*prim[i]; if (p < prim[cnt - 1]) { int index = Arrays.binarySearch(prim, p); System.out.print(index+" "); if (index>=0){ prim[index] = Integer.MAX_VALUE; count--; } } }*/ } } }
package com.supermars.practice; import java.util.Scanner; public class 直线上的点 { static Scanner cin = new Scanner(System.in); public static void main(String[] args) { // ax+by=c; while (cin.hasNext()) { int a = cin.nextInt(); int b = cin.nextInt(); int c = cin.nextInt(); int X1 = cin.nextInt();// [X1,X2] int X2 = cin.nextInt();// [Y1,Y2] int Y1 = cin.nextInt(); int Y2 = cin.nextInt(); int g = gcd(a, b); if (c % g != 0) {// g|c --->Xnew=c%g*X0 (k*X0,k=c%g,c%g==Int) System.out.println("NO"); continue; } int m = c % g, k = 1; if (m == 0) { k = c / g; for (int x = X1; x <= X2; x++) { double y = (c - a * x) / b; int yy = (int) y; if (y == yy && yy * k >= Y1 && yy * k <= Y2 && x * k >= X1 && x * k <= X2) { System.out.print(x * k + " " + yy * k + "\n"); } } } } } private static int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); } }
package com.supermars.practice; import java.util.Scanner; /** 123456789*987654321 123456789+987654321 123456789-987654321 * @author supermars * */ public class 同余与模算术 { static Scanner cin = new Scanner(System.in); public static void main(String[] args) { while (cin.hasNext()) { String s = cin.next(); String[] sa; String op = "*"; sa = s.split("\\*"); if (sa.length == 1) { sa = s.split("\\+"); op = "+"; if (sa.length == 1) { sa = s.split("\\-"); op = "-"; } } long a = Long.parseLong(sa[0]); long b = Long.parseLong(sa[1]); long ret = 0, n = 10; if (op == "*") { ret = mul_mod(a, b, n); } if (op == "+") { ret = add_mod(a, b, n); } if (op == "-") { ret = sub_mod(a, b, n); } System.out.println(ret); } } private static long sub_mod(long a, long b, long n) { a %= n; b %= n; return (a - b + n) % n; } private static long add_mod(long a, long b, long n) { return ((a %= n) + (b %= n)) % n; } private static long mul_mod(long a, long b, long n) { a %= n; b %= n; return a * b % n; } }
package com.supermars.practice; import java.util.Scanner; public class 大整数取模 { static Scanner cin = new Scanner(System.in); public static void main(String[] args) { while (cin.hasNext()) { String n = cin.next(); int m = cin.nextInt(); int ans = 0; for (int i = 0; i < n.length(); i++) { int t = ((int) n.charAt(i)); ans = (ans * 10 + t) % m; } System.out.println(ans); } } }
package com.supermars.practice; import java.util.Scanner; public class 幂取模 { static Scanner cin = new Scanner(System.in); public static void main(String[] args) { while (cin.hasNext()) { int a = cin.nextInt(); // a,n,m<=10^9 int n = cin.nextInt(); int m = cin.nextInt(); long ans = 1; for (int i = 1; i <= n; i++) { ans *= a % m; ans %= m; } // ab mode n =(a mode n)(b mode n)mode n System.out.println(ans % m); } } }
package com.supermars.practice; import java.util.Scanner; public class 模线性方程 { static Scanner cin = new Scanner(System.in); public static void main(String[] args) { while (cin.hasNext()) { int a = cin.nextInt(); int b = cin.nextInt(); int n = cin.nextInt(); int g = gcd(a, n); int k = (g % b == 0) ? g / b : 0; if (k == 0) System.out.println("No"); // 求解 ax-ny=b上的点 } } private static int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); } }