2020.3.24 Report problem-solving


\ [\ Text {happy burst zero.} \]

\[\text{By:LuckyBorder} \]


Answer case

Total score: 169 Ranking: NaN3
Tl: T2. 9: 100 T3: 60

Each subject analysis

Topic 1:
Estimated results: 20 Actual score: 9 examinations: 2:30 - 3:00, 4:00 - 5:00

Start Sike T1, launched a beautiful but relatively little use of the formula.
Read other questions after the first hit of the violence.

Topic 2:
100 examinations:: Estimated results: 100 Actual performance 3:00 - 3:20

Template title Fermat theorem small.
Before there is contact, done quickly.

Topic 3:
60 examinations:: Estimated results: 100 Actual performance 3:30 - 3:50

Previously done a similar block is divisible.
On this basis, we added some calculations.

Since the calculation of the lost burst longlong 40 minutes.

  • Lesson: Note that the data range! If the data range larger modulo time remember.

Analytical title

T1:

18 points:
violence enumeration s, violence determination.

100:
by playing table metaphysics can launch formula.


T2 :

Fermat's little theorem simple application.
Index is large, rapid exponential operation can not be performed directly.
Because the modulus is prime, the Fermat's little theorem, there are: \ (A ^ {P-. 1} \ equiv. 1 \ PMOD P \)
then \ (a ^ {b ^ c } \ equiv a ^ {b ^ c \ % (p - 1)} \ pmod p \)

And the base number of the index for fast power can take over.
Complexity \ (O (\ log k) \)


T3:

Divisible block simple applications.
For any \ (D \) , (\. 1 \ n-SIM) \ in which the number of times of occurrence factor \ (\ {n-dfrac} {D} \) .
It can be found in \ (\ dfrac {n} { d} \) in \ (D \) decremented is incremented.
The contribution of this factor to the answer is \ (\ lfloor \ {n-dfrac} {D} \ rfloor \ Times D ^ 2 \) .

For \ (1 \ sim n \) square and has formula: \ (\ {n-dfrac (n-+. 1) (2N +. 1). 6} {} \) .
Note \ (f (i) = \ dfrac {i (i + 1) (i + 1)} {6} \)

Because of \ (\ lfloor \ dfrac {n } {d} \ rfloor \) monotonically decreasing, there is a continuous range of many values.
For the number of occurrences are \ (\ dfrac {n} { i} \) factor \ (I \ J SIM \) ,
the total contribution of: \ ((F (J) - F (. 1-I)) \ Times \ lfloor \ dfrac {n} { i} \ rfloor \)

Obviously the above formula can be solved by blocking divisible.
For each block \ (\ lfloor \ dfrac {n } {i} \ rfloor \) interval, which contribution is the \ ((f (j) - f (i-1)) \ times \ lfloor \ dfrac {n} {i} \ rfloor \)

Note-taking at any time


Code

T1:

Examination room Code

//
/*
By:Luckyblock
*/
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#define ll long long
const int MARX = 110 + 10;
const int mod = 1e9 + 7;
//=============================================================
int N, K, Ans, f[MARX] = {1};
//=============================================================
inline int read()
{
    int f = 1, w = 0; char ch = getchar();
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) w = (w << 3) + (w << 1) + (ch ^ '0');
    return f * w;
}
//=============================================================
int main()
{
    freopen("cute.in", "r", stdin);
    freopen("cute.out", "w", stdout);
    N = read(), K = read();
    for(int i = 1; i <= N; i ++) f[i] = f[i - 1] * K;
    for(int s = 1; s < f[N]; s ++)
    {
      int flag = 1;
      for(int i = 1; i < N - 1; i ++)
        if(s % f[i] * f[N - i] <= s)
          {flag = 0; break;}
      Ans += flag, Ans %= mod;
    }
    printf("%d", Ans);
    return 0;
}

Correct

#include <iostream>
#include <algorithm>

using namespace std;

long long const P=1000000007,M=100000;
int m;
long long n,k,g[M],f[M];

bool isprime(long long x)
{
	if (x==1) return false;
	for (long long i=2;i*i<=x;i++)
		if (x % i==0) return false;
	return true;
}

long long comp(long long b,long long c,long long m)
{
	long long ans=1;
	long long l=b;
	long long j=1;
	while (j<=c)
	{
		if ((j & c)>0) ans=(ans*l) % m;
		j*=2;
		l=(l*l) % m; 
	}
	return ans;
}


int main()
{
	freopen("cute.in","r",stdin);
	freopen("cute.out","w",stdout);
	cin>>n>>k;
	for (long long i=1;i*i<=n;i++)
		if (n % i==0)
		{
			g[++m]=i;
			if (i*i<n) g[++m]=n/i;
		}
	sort(g+1,g+m+1);
	f[1]=k;
	for (int i=2;i<=m;i++)
	{
		f[i]=comp(k,g[i],P); 
		for (int j=1;j<=i-1;j++)
			if (g[i] % g[j]==0) f[i]=(f[i]+P-f[j]) % P;
	}
	printf("%lld\n",f[m]*comp(n,P-2,P) % P);
 } 


T2:

Examination codes (Positive Solution)

//
/*
By:Luckyblock
*/
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#define ll long long
//=============================================================
ll a, b, c, p;
//=============================================================
inline ll read()
{
    ll f = 1, w = 0; char ch = getchar();
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) w = (w << 3) + (w << 1) + (ch ^ '0');
    return f * w;
}
ll qpow(ll x, ll y, ll mod)
{
    ll ret = 1;
    for(; y; x = x * x % mod, y >>= 1)
      if(y & 1) ret = ret *x % mod;
    return ret;
}
//=============================================================
int main()
{
    freopen("number.in", "r", stdin);
    freopen("number.out", "w", stdout);
    a = read(), b = read(), c = read(), p = read();
    ll x = qpow(b, c, p - 1);
    printf("%lld", qpow(a, x, p));
    return 0;
}

T3:

Examination codes (Positive Solution)

//
/*
By:Luckyblock
*/
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#define ll long long
//=============================================================
ll N, Mod, ans, inv;
//=============================================================
inline ll read()
{
    ll f = 1, w = 0; char ch = getchar();
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) w = (w << 3) + (w << 1) + (ch ^ '0');
    return f * w;
}
ll qpow(ll x, ll y, ll mod)
{
    ll ret = 1;
    for(; y; x = x * x % mod, y >>= 1)
      if(y & 1) ret = ret * x % mod;
    return ret;
}
ll SquareSum(ll L, ll R)
{  
    ll suml =  L * (L + 1) % Mod * (2 * L % Mod + 1) % Mod * inv % Mod;
    ll sumr =  R * (R + 1) % Mod * (2 * R % Mod + 1) % Mod * inv % Mod;
    return (sumr - suml + Mod) % Mod;
}
//=============================================================
int main()
{
    N = read(), Mod = read();
    inv = qpow(6, Mod - 2, Mod);
    for(ll i = 1, j; i <= N; i = j + 1)
    {
      j = N / (N / i);
      ans = (ans + SquareSum((i - 1) % Mod , j % Mod) * (N / i) % Mod) % Mod;
    }
    printf("%lld\n", ans);
    system("pause");
    return 0;
}

Guess you like

Origin www.cnblogs.com/luckyblock/p/12566680.html