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 | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
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??