H y p e r l i n k Hyperlink Hyperlink
https://dev.xjoi.net/contest/1289/problem/1
D e s c r i p t i o n Description Description
若一个数 a a a通过旋转之后可以得到 b b b,则称 ( a , b ) (a,b) (a,b)是友好数对,给定 L , R L,R L,R求 L ∼ R L\sim R L∼R之间的友好数对个数
数据范围: L ≤ R ≤ 2 × 1 0 6 L\leq R \leq 2\times 10^6 L≤R≤2×106
S o l u t i o n Solution Solution
暴力
时间复杂度: O ( T l o g 10 R ( R − L + 1 ) ) O(Tlog_{10}R(R-L+1)) O(Tlog10R(R−L+1))
C o d e Code Code
#pragma GCC optimize(2)
#include<cstdio>
#include<cctype>
#include<algorithm>
#define LL long long
#define N 2000000
using namespace std;int t,pw,l,r,ans;
inline LL read()
{char c;LL d=1,f=0;while(c=getchar(),!isdigit(c)) if(c=='-') d=-1;f=(f<<3)+(f<<1)+c-48;while(c=getchar(),isdigit(c)) f=(f<<3)+(f<<1)+c-48;return d*f;
}
signed main()
{t=read();while(t--){l=read();r=read();ans=0;for(register int i=l;i<=r;i++){int x=i,pw=1,j=0;while(x) x/=10,j++,pw=(pw<<3)+(pw<<1);pw/=10;x=i;do{int high=x/pw;x%=pw;x=(x<<3)+(x<<1)+high;if(x<=r&&x>i) ans++;}while(x!=i);}printf("%d\n",ans);}
}