Here's the problem from last year's ACM ICPC Dhaka Regional Preliminary Round.
It says to calculate sod(n) [sum of digits of n] while n >= 10. Here n = a^b, (0<= a,b <= 10^50,000 and a+b>0 ) Any thoughts on how to solve this?
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Here's the problem from last year's ACM ICPC Dhaka Regional Preliminary Round.
It says to calculate sod(n) [sum of digits of n] while n >= 10. Here n = a^b, (0<= a,b <= 10^50,000 and a+b>0 ) Any thoughts on how to solve this?
Name |
---|
hint: divisibility rule by 9
At least if I correctly understood problem (I don't have access to your link)
I'm sorry , Here is the dropbox link of the all statements. It is there on page 12,Problem Statement : I
so, i guessed it right and hint I mentioned should help
It can be proven that the repeated digit sum of N is 1 + (N - 1) mod 9, so what you basically need to calculate ab mod 9.
It is well known that ab ≡ ab mod φ(M) (mod M) for (a, M) = 1.
A less known fact is ab ≡ aφ(M) + b mod φ(M) (mod M), for any a, M and b ≥ log(M). Using this and some case walk you can solve the problem.
However, there is another easy solution. That is, write b = b0 + b1·10 + b2·102 + ... + bn·10n. Now —
This product is easy, because now you can find each term by Binary Exponentiation.
include<bits/stdc++.h>
using namespace std;
int findBigMod(string number, int div){ int carry=0; int size = number.size(); for(int i=0;i<size;i++){ carry = carry * 10 + (number[i]-'0'); carry = carry % div; } return carry;
} int findPower(int base, int power){ int result=base; for(int i=1;i<power ; i++) result*=base; return result; } int main(){ int test; scanf("%d",&test); for(int i=1;i<=test;i++){ string base,power; cin>>base>>power; if(base== "0"){ printf("Case %d: 0\n",i); continue; } if(base=="3"){ if(power=="0"){ printf("Case %d: 1\n",i); } else if(power=="1") { printf("Case %d: 3\n",i); } else printf("Case %d: 9\n",i); continue; } if(power=="0"){ printf("Case %d: 1\n",i); continue; } int a= findBigMod(base,9); if(a==0) a=9; int b= findBigMod(power,6); b+=6;
return 0; }
can you tell me why I get WA in this problem??