結果
問題 |
No.6 使いものにならないハッシュ
|
ユーザー |
![]() |
提出日時 | 2018-03-01 01:27:00 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1,225 ms / 5,000 ms |
コード長 | 2,063 bytes |
コンパイル時間 | 797 ms |
コンパイル使用メモリ | 83,888 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-16 16:43:48 |
合計ジャッジ時間 | 11,592 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:69:28: warning: ‘start’ may be used uninitialized in this function [-Wmaybe-uninitialized] 69 | cout << sss[current]<<endl; | ^
ソースコード
#include <iostream> #include <string> #include <sstream> #include <vector> #include <math.h> #include <map> using namespace std; int hh(int x){ if(x<10)return x; ostringstream to_str; to_str << x; string str=to_str.str(); int sum=0; for(int i=0 ; i<str.size() ; i++ ){ string tmp="";tmp+=str[i]; istringstream to_int(tmp); int x; to_int>>x; sum+=x; } return hh(sum); } struct Info{ bool sign; int locate; }; int main(){ int N,K; cin >> N >> K; vector <int> prime; vector <int> sss; for(int i=N ; i<=K ; i++ ){ bool sign=true; for(int l=2 ; l<=sqrt(i) ; l++ ){ if(i%l==0){ sign=false; break; } } if(!sign || i==1 )continue; prime.push_back(hh(i)); sss.push_back(i); } vector<int>::iterator itr; map<int,Info> used; int current,counter=0,max=0; int start;bool sign=true; for(int i=0 ; i<prime.size() ; i++ ){ if(used[prime[i]].sign){ if(max<=counter){ max=counter; current=start; } used[prime[i]].sign=false; for(int j=0 ; j<i ; j++ ) used[prime[j]].sign=false; i=used[prime[i]].locate+1; sign=true; counter=0; }if(sign){ start=i; sign=false; } used[prime[i]].sign=true; used[prime[i]].locate=i; counter++; }if(max<=counter) current=start; cout << sss[current]<<endl; }