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?
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 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3603 |
| 4 | jiangly | 3583 |
| 5 | turmax | 3559 |
| 6 | tourist | 3541 |
| 7 | strapple | 3515 |
| 8 | ksun48 | 3461 |
| 9 | dXqwq | 3436 |
| 10 | Otomachi_Una | 3413 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 157 |
| 2 | adamant | 153 |
| 3 | Um_nik | 147 |
| 4 | Proof_by_QED | 146 |
| 5 | Dominater069 | 145 |
| 6 | errorgorn | 141 |
| 7 | cry | 139 |
| 8 | YuukiS | 135 |
| 9 | TheScrasse | 134 |
| 10 | chromate00 | 133 |
| 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;
int ans= findPower(a,b); if(ans%9 == 0 ) ans=9; else ans= ans%9; printf("Case %d: %d\n",i,ans); base.clear(); power.clear(); }return 0; }
can you tell me why I get WA in this problem??
Bcoz, You are Wrong!