timus 1104. Don’t Ask Woman about Her Age URAL 解题报告
来源:互联网 发布:进驻淘宝商城的条件 编辑:程序博客网 时间:2024/05/29 15:07
timus 1104. Don’t Ask Woman about Her Age URAL 解题报告
给一个数,但是不知道进制,然后找一个进制在2--36中,使其符合能整出(k-1),而且尽可能的小!
这种题不难就是进制转化,按照一般的朴素的方法写就行了,但是注意,如果输入的是0,那么只能输出进制是2,不能是1,因为要我们在2--36中寻找嘛!
还有注意取余时的一些操作!
a*b%mod==a%mod*(b%mod)%mod ,一定不要忘了1
(a+b%mod)%mod=(a+b)%mod
另外,注意此题最多多少位!
还有就是每一位上的数的权值不同啊!
代码:
#include <iostream>#include<string>#include<cstring>#include<cstdio>#include<cmath>#include<map>#include<cctype>using namespace std;int n,i,j,le1,le2;string a;long long sum,max1=0;long long b[1000009];void init(){ cin>>a; getchar(); n=a.length(); for(i=0; i<n; i++) { if(isupper(a[i])) b[i]=a[i]-'A'+10; else b[i]=a[i]-'0'; if(b[i]>max1) max1=b[i]; }}void solve(){ int gs=0; if(max1+1>36) { cout<<"No solution."<<endl; return; } if(max1<=1) {///这里注意如果读入的是一个0,只能写成他符合2进制,而不写1,因为题目让我们在2--36中寻找! cout<<2<<endl; return; } for(int k=max1+1; k<=36; k++) { int mod=(k-1); sum=b[0]%mod;///注意这里没有放到for里面,如果忘了取模而恰巧该数就1位的话就惨了…… int tmp=k; for(int t=1; t<n; t++) { sum+=(b[t]%mod*(tmp%mod) )%mod; sum%=mod; tmp=tmp*tmp%mod; } if(sum==0) { gs=1; cout<<k<<endl; break; } } if(gs==0) cout<<"No solution."<<endl;}int main(){ init(); solve(); return 0;}
timus 1104. Don’t Ask Woman about Her Age URAL 解题报告
- timus 1104. Don’t Ask Woman about Her Age URAL 解题报告
- Timus 1104. Don’t Ask Woman about Her Age题解
- Timus 1104. Don’t Ask Woman about Her Age
- ural 1104. Don’t Ask Woman about Her Age
- Ural 1104. Don’t Ask Woman about Her Age
- Timus 1104 Don’t Ask Woman about Her Age
- Don’t Ask Woman about Her Age
- 1104. Don't ask woman about her age
- timus 1167. Bicolored Horses URAL 解题报告
- timus 1029. Ministry URAL 解题报告
- timus 1036. Lucky Tickets URAL 解题报告
- timus 1287. Mars Canals URAL 解题报告
- timus 1513. Lemon Tale URAL 解题报告
- timus 1244. Gentlemen URAL 解题报告
- timus 1319. Hotel URAL 解题报告
- timus 1149. Sinus Dances URAL 解题报告
- Tell, Don't Ask
- Tell,Don’t Ask!
- Web Service实际开发
- ubuntu tftp服务器
- OK6410启动代码(1)
- hdu 4510 小Q系列故事――为什么时光不能倒流
- ARM Cortex M3 启动文件分析
- timus 1104. Don’t Ask Woman about Her Age URAL 解题报告
- 大二快要结束的暑假
- OK6410启动代码(2)
- Spell Checker
- python crawler0729.py
- shell笔记(五)——函数
- 一个音效播放类SoundManager
- eclipse 快捷运用
- 数据库2008登不上" 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误"