2022-01-14

66 阅读1分钟
import java.util.Scanner;
public class Main{
    static int N = 100010;
    static long res;
    public static long qmi(long a,int k,int p ){
        res = 1;
        while( k != 0){
            if((k & 1) != 0) res = res * a % p;
            k >>= 1;
            a = a * a % p;
        }
        return res;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while(n-- > 0){
            int a = sc.nextInt();
            int k = sc.nextInt();
            int p = sc.nextInt();
            System.out.println(qmi(a,k,p));
          
        }
    }
}
import java.util.Scanner;
public class Main{
    static int N = 100010;
    static long res ;
    public static long qmi(long a,int k,int p){
        res  = 1;
        while(k != 0){
            if((k & 1) != 0) res = res * a % p;
            k >>= 1;
            a = a * a %p;
        }
        return res;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while(n-- > 0){
            int a = sc.nextInt();
            int p = sc.nextInt();
            if(a % p != 0){
                System.out.println(qmi(a,p - 2,p));
            }else{
                System.out.println("impossible");
            }
        }
    }
}
import java.util.*;
public class Main{
    static int N = 110;
    static double[][] a = new double[N][N];
    static double eps = 1e-6;
    static int n;
    public static int guass(){
        int row = 0,col = 0;
        for(col = 0;col < n;col++){
            int t = row;
            for(int i = row; i < n; i++){
                if(Math.abs(a[i][col]) > Math.abs(a[t][col])){
                    t = i;
                }
            }
            if(Math.abs(a[t][col]) < eps) continue;
            
            for(int i = col; i <= n; i++){
                double temp = a[row][i];
                a[row][i] = a[t][i];
                a[t][i] = temp;
            }
            
            for(int i = n; i >= col; i--){
                a[row][i] /= a[row][col]; 
            }
            
            for(int i = row + 1; i < n;i++){
                for(int j = n; j >= col; j--){
                    a[i][j] -= a[row][j] * a[i][col];
                }
            }
            
            row++;
        }
        if(row < n){
            for(int i = row; i < n;i++ ){
                if(Math.abs(a[i][n]) > eps) return 2;
            }
            return 1;
        }
        
        for(int i = n - 1; i >= 0;i--){
            for(int j = i + 1;j < n ; j++){
                a[i][n] -= a[j][n] * a[i][j];
            }
        }
        return 0;
    }
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        for(int i = 0; i < n; i++){
            for(int j = 0; j <= n; j++){
                a[i][j] = sc.nextDouble();
            }
        }
        int t = guass();
        if(t == 0){
            for(int i = 0; i < n;i++){
                if(Math.abs(a[i][n]) < eps){
                    System.out.printf("%.2f\n",Math.abs(a[i][n]));
                }else{
                    System.out.printf("%.2f\n",a[i][n]);
                }
            }
        }else if(t==1){
             System.out.println("Infinite group solutions");
         }else{
             System.out.println("No solution");
         }
    }
}
import java.util.Scanner;
public class Main{
    static int N = 2010;
    static int[][] c = new int[N][N];
    static int INF = (int)1e9 + 7;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i = 0; i < N;i ++){
            for(int j = 0; j <= i; j++){
                if(j == 0){
                    c[i][j] = 1;
                }else{
                    c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % INF;
                }
            }
        }
        while(n-- > 0){
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println(c[a][b]);
        }
    }
}
import java.util.Scanner;
public class Main{
    static long res;
    static int N = 100010;
    static long[] fact = new long[N];
    static long[] infact = new long[N];
    static int mod = (int) 1e9 + 7;
    public static long qmi(long a,int k,int p){
        res = 1;
        while(k != 0){
            if((k & 1) != 0) res = res * a % p;
            k >>= 1;
            a = a * a % p;
        }
        return res;
    }
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        fact[0] = infact[0] = 1;
        for(int i = 1; i < N;i++){
            fact[i] = fact[i - 1] * i % mod;
            infact[i] = infact[i - 1] * qmi(i,mod - 2,mod) % mod;
        }
        while(n-- > 0){
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println((fact[a] * infact[a- b] % mod) * infact[b] %mod);
        }
    }
}