original link: https://www.dreamwings.cn/hdu5690/2657.html
All X
Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 703 accepted Submission (s): 328
Problem Description F (x,m) represents an M-digit number consisting entirely of a number x. Please calculate whether the following formula is valid:
F (x,m) mod k≡c
Input first line an integer t that represents the T-group data.
One row for each set of test data, containing four digits x,m,k,c
1≤x≤9
1≤m≤1010
0≤c<k≤10,000
Output two lines for each set of data:
First line output: "Case #i:". I represents the group I test data.
The second line outputs "Yes" or "No", representing four digits and whether the formula given in the topic can be met.
Sample Input
3 1 3 5 2 1 3 5 1 3 5 99-69
Sample Output
Case #1: No. #2: Yes Hint for the first set of test data: 5 = 1, the formula does not hold, so the answer is "no", and the second set of test data satisfies the formula above, so the answer is "yes".
Source 2016 "Baidu Star"-Preliminary (Astar round2a)
General output only yes or no questions are regular ~ Seniors said, and then the general test data over the submission is always wrong answer. A number of m digits consisting of X can also be represented as (10^m-1) *X/9, right. In this case, only need to prove ((10^m-1) *x)/9%k==c set up on it. You can change this equation, that is ((10^m)% (9*k) *x)% (9*k)-x==9*c; Then seconds A.
AC Code:
#include <iostream>
#include <stdio.h>
typedef long long LL;
using namespace std;
ll Modexp (ll a,ll b,ll N)
{
ll ret=1;
LL Tmp=a;
while (b)
{
//cardinality exists
if (b&0x1) ret=ret*tmp%n;
tmp=tmp*tmp%n;
b>>=1;
}
return ret;
}
int main ()
{
//printf ("%d\n", Modexp (3,2,5));
int N;
cin>>n;
for (int i=1;i<=n;i++)
{
LL x,m,k,c;
cin>>x>>m>>k>>c;
LL Mo=9*k;
LL a= (Modexp (10,M,MO) *x)%mo-x;
printf ("Case #%d:\n", i);
if (a==9*c) printf ("yes\n");
else printf ("no\n");
}
return 0;
}