zoukankan      html  css  js  c++  java
  • 小凯的数字 数论

    https://www.luogu.org/problemnew/show/P4942

    上面为原题地址;

    引理:

    一个数字除以9的余数等于它的各位数字之和除以9的余数

    那么我们将其各个数字加起来%9即可;

    当然用等差数列公式更快;

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstdlib>
    #include<cstring>
    #include<string>
    #include<cmath>
    #include<map>
    #include<set>
    #include<vector>
    #include<queue>
    #include<bitset>
    #include<ctime>
    #include<deque>
    #include<stack>
    #include<functional>
    #include<sstream>
    //#include<cctype>
    //#pragma GCC optimize("O3")
    using namespace std;
    #define maxn 400005
    #define inf 0x3f3f3f3f
    #define INF 9999999999
    #define rdint(x) scanf("%d",&x)
    #define rdllt(x) scanf("%lld",&x)
    #define rdult(x) scanf("%lu",&x)
    #define rdlf(x) scanf("%lf",&x)
    #define rdstr(x) scanf("%s",x)
    typedef long long  ll;
    typedef unsigned long long ull;
    typedef unsigned int U;
    #define ms(x) memset((x),0,sizeof(x))
    const long long int mod = 1e9 + 7;
    #define Mod 1000000000
    #define sq(x) (x)*(x)
    #define eps 1e-3
    typedef pair<int, int> pii;
    #define pi acos(-1.0)
    const int N = 1005;
    #define REP(i,n) for(int i=0;i<(n);i++)
    typedef pair<int, int> pii;
    inline ll rd() {
    	ll x = 0;
    	char c = getchar();
    	bool f = false;
    	while (!isdigit(c)) {
    		if (c == '-') f = true;
    		c = getchar();
    	}
    	while (isdigit(c)) {
    		x = (x << 1) + (x << 3) + (c ^ 48);
    		c = getchar();
    	}
    	return f ? -x : x;
    }
    
    ll gcd(ll a, ll b) {
    	return b == 0 ? a : gcd(b, a%b);
    }
    ll sqr(ll x) { return x * x; }
    
    /*ll ans;
    ll exgcd(ll a, ll b, ll &x, ll &y) {
    	if (!b) {
    		x = 1; y = 0; return a;
    	}
    	ans = exgcd(b, a%b, x, y);
    	ll t = x; x = y; y = t - a / b * y;
    	return ans;
    }
    */
    
    
    
    ll qpow(ll a, ll b, ll c) {
    	ll ans = 1;
    	a = a % c;
    	while (b) {
    		if (b % 2)ans = ans * a%c;
    		b /= 2; a = a * a%c;
    	}
    	return ans;
    }
    
    
    int T;
    ll l, r, cnt;
    
    int main()
    {
    	//ios::sync_with_stdio(0);
    	rdint(T);
    	while (T--) {
    		rdllt(l); rdllt(r);
    		cnt = (r - l + 1);
    		if (cnt % 2 == 0) {
    			cout << ((cnt / 2) % 9 * (l + r) % 9) % 9 << endl;
    		}
    		else if ((r + l) % 2 == 0) {
    			cout << ((cnt) % 9 * ((l + r) / 2) % 9) % 9 << endl;
    		}
    	}
    	
    
        return 0;
    }
    
    EPFL - Fighting
  • 相关阅读:
    MySql控制台命令
    MySql笔记
    Unity打包android时会出的一些问题
    Unity3D2017.3.0基于Vuforia 开发AR流程(1)
    基于Unity开发广州幻境的Handy结合HTC Tracker的开发坑
    基于Unity 关于SteamVR中 手柄/Tracker不显示的问题
    使用Socket对序列化数据进行传输(基于C#)
    7. 整数反转
    6. Z 字形变换
    53. 最大子序和
  • 原文地址:https://www.cnblogs.com/zxyqzy/p/9966931.html
Copyright © 2011-2022 走看看