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 | jiangly | 3898 |
2 | tourist | 3840 |
3 | orzdevinwang | 3706 |
4 | ksun48 | 3691 |
5 | jqdai0815 | 3682 |
6 | ecnerwala | 3525 |
7 | gamegame | 3477 |
8 | Benq | 3468 |
9 | Ormlis | 3381 |
10 | maroonrk | 3379 |
# | User | Contrib. |
---|---|---|
1 | cry | 168 |
2 | -is-this-fft- | 165 |
3 | Dominater069 | 161 |
4 | Um_nik | 159 |
4 | atcoder_official | 159 |
6 | djm03178 | 157 |
7 | adamant | 153 |
8 | luogu_official | 150 |
9 | awoo | 149 |
10 | TheScrasse | 146 |
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??