結果
問題 |
No.915 Plus Or Multiple Operation
|
ユーザー |
|
提出日時 | 2020-03-10 04:06:06 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 151 ms / 2,000 ms |
コード長 | 586 bytes |
コンパイル時間 | 2,212 ms |
コンパイル使用メモリ | 74,976 KB |
実行使用メモリ | 41,616 KB |
最終ジャッジ日時 | 2024-11-07 03:45:28 |
合計ジャッジ時間 | 4,586 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 |
ソースコード
import java.util.ArrayList; import java.util.Scanner; class Main { public static void main(String[] args) { new Main().run(); } long solve(long A,long B,long C) { if(C==1&&A>1)return -1; long ans=0; while(A>0) { if(C<=A&&A<=2*C-2) { A=0; ans+=B; }else if(A%C!=0) { A-=A%C; }else { A/=C; } ans+=B; } return ans; } void run() { Scanner sc=new Scanner(System.in); int Q=sc.nextInt(); for(int q=0;q<Q;++q) { long A=sc.nextLong(); long B=sc.nextLong(); long C=sc.nextLong(); System.out.println(solve(A,B,C)); } } }