Decimal point (Euler's theorem)

Link
Meaning:

Idea:
f ( i ) f(i) f(i) the conclusion is that if i i If i contains only 2 and 5, then it is 0, otherwise it is m a x ( m c ( 2 ) , m c ( 5 ) ) + 1 max(mc(2),mc(5))+1 max(mc(2),mc(5))+1, m c mc mc stands for the power of i. why? Let's prove it roughly
Suppose the length of the current loop section is n, and then the shape starting from the first bit, such as
1 i = 0. { k } { k } { k } . . . , that Do you I Guys false set up 1 i = 0. { k } { k } { k } . . 1 two edge with Time ride with 1 0 n also Just yes 1 0 n ∗ 1 i = { k } . { k } { k } { k } . . 2 2 − 1 have to     1 i = { k } 1 0 n − 1 ( 1 ) however after yes two individual junction theory , as fruit i and 10 mutual quality , also Just yes g c d ( i , 10 ) = = 1 , that Do you one set can surface show become ( 1 ) Persimmon son , from to Oh PULL set reason 1 0 x = 1 ( m o d   i ) , with Time x etc. to ϕ ( i ) Time Wait become stand that Do you   1 0 n = 1 + k ∗ i very Allow easy Just can have to reach 1 type junction theory 2 , as fruit no and 10 mutual quality , also Just yes yes 2 or person 5 quality because son g c d ( i , 10 ) ≠ 1 can with hair present each Pick except one yes 2 and 5 , { k } Just meeting to front shift move one position that Do you I Guys need want Pick except 2 and 5 , also Just yes m a x ( m c ( 2 ) , m c ( 5 ) ) present stay Test Worry about as What Unified meter , from to power second yes l o g level other of , I Guys Violent power Pieces lift 2 and 5 of power second however after present stay only need want Unified meter no Save stay 2 and 5 of because son of feeling condition , that Do you Allow Denounce one lower Just can with Yes reduce go 2 and 5 again plus upper 10 \There's a{{{{{{{{{{{{{\} \ {{{{\} \ {{{\ {{{{\ {{{{{{\} \ {{{\} \ {{{\ {\} {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{} {{{{{\} {{\} {{{{{{{{{} {{{{{{{{{{{{{{{{{{{}} {thatis gcd(i,10)==1, \ \ then it must be expressed as (1) persimmon, Since Euler's theorem 10^{x}=1(mod~i), \ \ holds when x is equal to \ phi(i) \ \ then ~ 10^{n}=1+k*i can easily get formula 1 \ \ conclusion 2. If it is not coprime with 10, that is, there are 2 or 5 prime factors \ \ gcd(i,10)\neq1 \ \ it can be found that \ {K \} will move forward one bit for each pair of 2 and 5 removed \ \ then we need to remove 2 and 5, that is, max(mc(2),mc(5)) \Now consider how to count. Since the power is at the log level, we violently enumerate the powers of 2 and 5 \ \ now we only need to count the cases where there are no factors of 2 and 5, so it's OK to exclude \ \ subtract 2 and 5 and add 10 i1 = 0.{k}{k}{k}... So let's assume that i1 = 0. {K} {K}.. 1 both sides are multiplied by 10n at the same time, that is, 10n * i1 = {K}. {K} {K}.. 22 − 1     i1 = 10n − 1{k} (1). Then there are two conclusions. If I and 10 are coprime, that is, gcd(i,10)==1, it must be expressed as (1) persimmon, because Euler's theorem 10x=1(mod)   i) And x equals ϕ (i) When was it established   10n=1+k * I can easily get the conclusion 2 of Formula 1. If it is not coprime with 10, that is, there are 2 or 5 prime factors gcd(i,10)  = 1, it can be found that {K} will move forward one bit every time a pair of 2 and 5 are eliminated. Then we need to eliminate 2 and 5, that is, max(mc(2),mc(5)) now consider how to count. Because the power is at the log level, We violently enumerate the powers of 2 and 5, and now we only need to count the cases where there are no factors of 2 and 5, so we can exclude it, subtract 2 and 5 and add 10
AC Code:

//#pragma GCC target("avx")
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast")
// created by myq
#include<iostream>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cctype>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
#define x first
#define y second
typedef pair<int,int> pii;
const int N = 400010;
const int mod=998244353;
inline int read()
{
	int res=0;
	int f=1;
	char c=getchar();
	while(c>'9' ||c<'0')
	{
		if(c=='-')	f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		res=(res<<3)+(res<<1)+c-'0';
	}
	return res;
 }
 #define int long long
int solve(int x){
	int now=1;
	int res=0;	
	for(int i=0;i<=60;i++){
		int nn=now;
		int cost=i;
		if(nn>x)
		break;
		for(int j=0;;j++){
			cost=max(i,j)+1;	
			int cnt=x/nn;
		
			res+=max(0ll,(cnt-cnt/2-cnt/5+cnt/10-1))%mod*cost%mod;
			res%=mod;
			nn*=5;
			if(nn>x)
			break;
		}	
		now*=2;
	}
//	cout<<res<<endl;
	return res;
}
signed main()
{
	 ios::sync_with_stdio(0);
	 cin.tie(0);
	 cout.tie(0);
	 int q;
	 cin>>q;
	 while(q--){
	 	int l,r;
	 	cin>>l>>r;
	 	cout<<(solve(r)-solve(l-1)+mod)%mod<<endl;
	 }
	return 0;

}
/**
* In every life we have some trouble
* When you worry you make it double
* Don't worry,be happy.
**/



Tags: Algorithm number theory linear algebra

Posted on Fri, 01 Oct 2021 16:02:56 -0400 by explore