zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    17字符串函数
    16数学函数
    计算文件的相对路径
    PHP生成唯一ID的方法
    PHP高效产生m个n范围内的不重复随机数(m<=n)
    随机红包
    约瑟夫环问题
    求n以内的质数(质数的定义:在大于1的自然数中,除了1和它本身意外,无法被其他自然数整除的数)
    10个值得深思的_PHP_面试问题
    PHP中被忽略的性能优化利器:生成器
  • 原文地址:https://www.cnblogs.com/pyyyyyy/p/10888331.html
Copyright © 2011-2022 走看看