• P2613 【模板】有理数取余


    数论一道题也不会,下午考试怎么办啊!!

    题目链接:

    P2613 【模板】有理数取余

    思路:

    然后就改一下下快读,直接暴力搞... 但是只得了10分,WOC!!

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<algorithm>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<vector>
    #define ll long long int
    #include<stack>
    #include<queue>
    using namespace std;
    inline int read() {
    	char c = getchar();
    	int x = 0, f = 1;
    	while(c < '0' || c > '9') {
    		if(c == '-') f = -1;
    		c = getchar();
    	}
    	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    	return x * f % 19260817;
    }
    ll quickpow(ll a, int b) {
    	ll ret = 1;
    	while(b) {
    		if(b & 1)
    			ret = ret*a%19260817;
    		a=a*a% 19260817;
    		b>>=1;
    	}
    	return ret%19260817;
    }
    int main() {
    	ll a = read(), b = read();
    	if(!b) {
    		printf("Angry!
    ");
    		return 0;
    	}
    	ll ans = (a%19260817)*(quickpow(b,19260817-2)%19260817)%19260817;
    	cout<<ans%19260817;
    }
    

    后来看了大佬的题解又比着打了一遍,太菜了

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<algorithm>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<vector>
    #include<stack>
    #include<queue>
    using namespace std;
    #define enter puts("") 
    #define space putchar(' ')
    #define Mem(a, x) memset(a, x, sizeof(a))
    #define rg register
    typedef long long ll;
    typedef double db;
    const int INF = 0x3f3f3f3f;
    const db eps = 1e-8;
    const int mod = 19260817;
    inline ll read()
    {
        ll ans = 0;
        char ch = getchar(), last = ' ';
        while(!isdigit(ch)) {last = ch; ch = getchar();}
        while(isdigit(ch)) {ans = ans * 10 % mod + ch - '0'; ch = getchar();}
        ans %= mod;
        if(last == '-') ans = -ans;
        return ans;
    }
    inline void write(ll x)
    {
        if(x < 0) x = -x, putchar('-');
        if(x >= 10) write(x / 10);
        putchar(x % 10 + '0');
    }
    
    ll quickpow(ll a, int b)
    {
        ll ret = 1;
        while(b)
        {
            if(b & 1) ret = ret * a % mod;
            a = a * a % mod; b >>= 1;
        }
        return ret;
    }
    
    int main()
    {
        ll a = read(), b = read();
        if(!b) {printf("Angry!
    "); return 0;}
        ll ans = a * quickpow(b, mod - 2) % mod;
        write(ans); enter;
    }
    
  • 相关阅读:
    【Git】git使用
    【Git】git使用
    【Git】git使用
    【spring boot】SpringBoot初学(8)– 简单整合redis
    「Flink」使用Managed Keyed State实现计数窗口功能
    「Flink」Flink的状态管理与容错
    「数据挖掘入门序列」数据挖掘模型分类与预测
    「Flink」使用Java lambda表达式实现Flink WordCount
    Java 8 函数式编程
    「数据挖掘入门系列」数据挖掘模型之分类和预测
  • 原文地址:https://www.cnblogs.com/pyyyyyy/p/10888331.html
Copyright © 2020-2023  润新知